
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.io.vasp.outputs &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.vasp.outputs</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.vasp.outputs</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Classes for reading/manipulating/writing VASP ouput files.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">glob</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
<span class="kn">import</span> <span class="nn">xml.etree.cElementTree</span> <span class="k">as</span> <span class="nn">ET</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">defaultdict</span>
<span class="kn">from</span> <span class="nn">io</span> <span class="kn">import</span> <span class="n">StringIO</span>
<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">List</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.interpolate</span> <span class="kn">import</span> <span class="n">RegularGridInterpolator</span>
<span class="kn">from</span> <span class="nn">monty.io</span> <span class="kn">import</span> <span class="n">zopen</span><span class="p">,</span> <span class="n">reverse_readfile</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">jsanitize</span>
<span class="kn">from</span> <span class="nn">monty.re</span> <span class="kn">import</span> <span class="n">regrep</span>
<span class="kn">from</span> <span class="nn">monty.os.path</span> <span class="kn">import</span> <span class="n">zpath</span>
<span class="kn">from</span> <span class="nn">monty.dev</span> <span class="kn">import</span> <span class="n">deprecated</span>

<span class="kn">from</span> <span class="nn">pymatgen.core.composition</span> <span class="kn">import</span> <span class="n">Composition</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.lattice</span> <span class="kn">import</span> <span class="n">Lattice</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Element</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.units</span> <span class="kn">import</span> <span class="n">unitized</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.bandstructure</span> <span class="kn">import</span> <span class="n">BandStructure</span><span class="p">,</span> \
    <span class="n">BandStructureSymmLine</span><span class="p">,</span> <span class="n">get_reconstructed_band_structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.core</span> <span class="kn">import</span> <span class="n">Spin</span><span class="p">,</span> <span class="n">Orbital</span><span class="p">,</span> <span class="n">OrbitalType</span><span class="p">,</span> <span class="n">Magmom</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.dos</span> <span class="kn">import</span> <span class="n">CompleteDos</span><span class="p">,</span> <span class="n">Dos</span>
<span class="kn">from</span> <span class="nn">pymatgen.entries.computed_entries</span> <span class="kn">import</span> \
    <span class="n">ComputedEntry</span><span class="p">,</span> <span class="n">ComputedStructureEntry</span>
<span class="kn">from</span> <span class="nn">pymatgen.io.wannier90</span> <span class="kn">import</span> <span class="n">Unk</span>
<span class="kn">from</span> <span class="nn">pymatgen.io.vasp.inputs</span> <span class="kn">import</span> <span class="n">Incar</span><span class="p">,</span> <span class="n">Kpoints</span><span class="p">,</span> <span class="n">Poscar</span><span class="p">,</span> <span class="n">Potcar</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.io_utils</span> <span class="kn">import</span> <span class="n">clean_lines</span><span class="p">,</span> <span class="n">micro_pyawk</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.num</span> <span class="kn">import</span> <span class="n">make_symmetric_matrix_from_upper_tri</span>


<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong, Geoffroy Hautier, Rickard Armiento, &quot;</span> <span class="o">+</span> \
             <span class="s2">&quot;Vincent L Chevrier, Ioannis Petousis, Stephen Dacek, Mark Turiansky&quot;</span>
<span class="n">__credits__</span> <span class="o">=</span> <span class="s2">&quot;Anubhav Jain&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2011, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.2&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;shyuep@gmail.com&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s2">&quot;Production&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Nov 30, 2012&quot;</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">_parse_parameters</span><span class="p">(</span><span class="n">val_type</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Helper function to convert a Vasprun parameter into the proper type.</span>
<span class="sd">    Boolean, int and float types are converted.</span>

<span class="sd">    Args:</span>
<span class="sd">        val_type: Value type parsed from vasprun.xml.</span>
<span class="sd">        val: Actual string value parsed for vasprun.xml.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">val_type</span> <span class="o">==</span> <span class="s2">&quot;logical&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">val</span> <span class="o">==</span> <span class="s2">&quot;T&quot;</span>
    <span class="k">elif</span> <span class="n">val_type</span> <span class="o">==</span> <span class="s2">&quot;int&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">val_type</span> <span class="o">==</span> <span class="s2">&quot;string&quot;</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">val</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">_parse_v_parameters</span><span class="p">(</span><span class="n">val_type</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">param_name</span><span class="p">):</span>
    <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Helper function to convert a Vasprun array-type parameter into the proper</span>
<span class="sd">    type. Boolean, int and float types are converted.</span>

<span class="sd">    Args:</span>
<span class="sd">        val_type: Value type parsed from vasprun.xml.</span>
<span class="sd">        val: Actual string value parsed for vasprun.xml.</span>
<span class="sd">        filename: Fullpath of vasprun.xml. Used for robust error handling.</span>
<span class="sd">            E.g., if vasprun.xml contains *** for some Incar parameters,</span>
<span class="sd">            the code will try to read from an INCAR file present in the same</span>
<span class="sd">            directory.</span>
<span class="sd">        param_name: Name of parameter.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Parsed value.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">val_type</span> <span class="o">==</span> <span class="s2">&quot;logical&quot;</span><span class="p">:</span>
        <span class="n">val</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="o">==</span> <span class="s2">&quot;T&quot;</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">val</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
    <span class="k">elif</span> <span class="n">val_type</span> <span class="o">==</span> <span class="s2">&quot;int&quot;</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">val</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">val</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="c1"># Fix for stupid error in vasprun sometimes which displays</span>
            <span class="c1"># LDAUL/J as 2****</span>
            <span class="n">val</span> <span class="o">=</span> <span class="n">_parse_from_incar</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">param_name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">val</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s2">&quot;Error in parsing vasprun.xml&quot;</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">val_type</span> <span class="o">==</span> <span class="s2">&quot;string&quot;</span><span class="p">:</span>
        <span class="n">val</span> <span class="o">=</span> <span class="n">val</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">val</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">val</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="c1"># Fix for stupid error in vasprun sometimes which displays</span>
            <span class="c1"># MAGMOM as 2****</span>
            <span class="n">val</span> <span class="o">=</span> <span class="n">_parse_from_incar</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">param_name</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">val</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">IOError</span><span class="p">(</span><span class="s2">&quot;Error in parsing vasprun.xml&quot;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">val</span>


<span class="k">def</span> <span class="nf">_parse_varray</span><span class="p">(</span><span class="n">elem</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">elem</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;logical&#39;</span><span class="p">:</span>
        <span class="n">m</span> <span class="o">=</span> <span class="p">[[</span><span class="kc">True</span> <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="s1">&#39;T&#39;</span> <span class="k">else</span> <span class="kc">False</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">elem</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">m</span> <span class="o">=</span> <span class="p">[[</span><span class="n">_vasprun_float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">elem</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">m</span>


<span class="k">def</span> <span class="nf">_parse_from_incar</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Helper function to parse a parameter from the INCAR.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">dirname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">dirname</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;INCAR&quot;</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;INCAR found. Using &quot;</span> <span class="o">+</span> <span class="n">key</span> <span class="o">+</span> <span class="s2">&quot; from INCAR.&quot;</span><span class="p">)</span>
            <span class="n">incar</span> <span class="o">=</span> <span class="n">Incar</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">incar</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">incar</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">None</span>
    <span class="k">return</span> <span class="kc">None</span>


<span class="k">def</span> <span class="nf">_vasprun_float</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Large numbers are often represented as ********* in the vasprun.</span>
<span class="sd">    This function parses these values as np.nan</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">f</span> <span class="o">==</span> <span class="s1">&#39;*&#39;</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s1">&#39;Float overflow (*******) encountered in vasprun&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span>
        <span class="k">raise</span> <span class="n">e</span>


<div class="viewcode-block" id="Vasprun"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Vasprun">[docs]</a><span class="k">class</span> <span class="nc">Vasprun</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Vastly improved cElementTree-based parser for vasprun.xml files. Uses</span>
<span class="sd">    iterparse to support incremental parsing of large files.</span>
<span class="sd">    Speedup over Dom is at least 2x for smallish files (~1Mb) to orders of</span>
<span class="sd">    magnitude for larger files (~10Mb).</span>

<span class="sd">    **Vasp results**</span>

<span class="sd">    .. attribute:: ionic_steps</span>

<span class="sd">        All ionic steps in the run as a list of</span>
<span class="sd">        {&quot;structure&quot;: structure at end of run,</span>
<span class="sd">        &quot;electronic_steps&quot;: {All electronic step data in vasprun file},</span>
<span class="sd">        &quot;stresses&quot;: stress matrix}</span>

<span class="sd">    .. attribute:: tdos</span>

<span class="sd">        Total dos calculated at the end of run.</span>

<span class="sd">    .. attribute:: idos</span>

<span class="sd">        Integrated dos calculated at the end of run.</span>

<span class="sd">    .. attribute:: pdos</span>

<span class="sd">        List of list of PDos objects. Access as pdos[atomindex][orbitalindex]</span>

<span class="sd">    .. attribute:: efermi</span>

<span class="sd">        Fermi energy</span>

<span class="sd">    .. attribute:: eigenvalues</span>

<span class="sd">        Available only if parse_eigen=True. Final eigenvalues as a dict of</span>
<span class="sd">        {(spin, kpoint index):[[eigenvalue, occu]]}.</span>
<span class="sd">        This representation is based on actual ordering in VASP and is meant as</span>
<span class="sd">        an intermediate representation to be converted into proper objects. The</span>
<span class="sd">        kpoint index is 0-based (unlike the 1-based indexing in VASP).</span>

<span class="sd">    .. attribute:: projected_eigenvalues</span>

<span class="sd">        Final projected eigenvalues as a dict of {spin: nd-array}. To access</span>
<span class="sd">        a particular value, you need to do</span>
<span class="sd">        Vasprun.projected_eigenvalues[spin][kpoint index][band index][atom index][orbital_index]</span>
<span class="sd">        This representation is based on actual ordering in VASP and is meant as</span>
<span class="sd">        an intermediate representation to be converted into proper objects. The</span>
<span class="sd">        kpoint, band and atom indices are 0-based (unlike the 1-based indexing</span>
<span class="sd">        in VASP).</span>


<span class="sd">    .. attribute:: other_dielectric</span>

<span class="sd">        Dictionary, with the tag comment as key, containing other variants of</span>
<span class="sd">        the real and imaginary part of the dielectric constant (e.g., computed</span>
<span class="sd">        by RPA) in function of the energy (frequency). Optical properties (e.g.</span>
<span class="sd">        absorption coefficient) can be obtained through this.</span>
<span class="sd">        The data is given as a tuple of 3 values containing each of them</span>
<span class="sd">        the energy, the real part tensor, and the imaginary part tensor</span>
<span class="sd">        ([energies],[[real_partxx,real_partyy,real_partzz,real_partxy,</span>
<span class="sd">        real_partyz,real_partxz]],[[imag_partxx,imag_partyy,imag_partzz,</span>
<span class="sd">        imag_partxy, imag_partyz, imag_partxz]])</span>

<span class="sd">    .. attribute:: nionic_steps</span>

<span class="sd">        The total number of ionic steps. This number is always equal</span>
<span class="sd">        to the total number of steps in the actual run even if</span>
<span class="sd">        ionic_step_skip is used.</span>

<span class="sd">    .. attribute:: force_constants</span>

<span class="sd">        Force constants computed in phonon DFPT run(IBRION = 8).</span>
<span class="sd">        The data is a 4D numpy array of shape (natoms, natoms, 3, 3).</span>

<span class="sd">    .. attribute:: normalmode_eigenvals</span>

<span class="sd">        Normal mode frequencies.</span>
<span class="sd">        1D numpy array of size 3*natoms.</span>

<span class="sd">    .. attribute:: normalmode_eigenvecs</span>

<span class="sd">        Normal mode eigen vectors.</span>
<span class="sd">        3D numpy array of shape (3*natoms, natoms, 3).</span>

<span class="sd">    **Vasp inputs**</span>

<span class="sd">    .. attribute:: incar</span>

<span class="sd">        Incar object for parameters specified in INCAR file.</span>

<span class="sd">    .. attribute:: parameters</span>

<span class="sd">        Incar object with parameters that vasp actually used, including all</span>
<span class="sd">        defaults.</span>

<span class="sd">    .. attribute:: kpoints</span>

<span class="sd">        Kpoints object for KPOINTS specified in run.</span>

<span class="sd">    .. attribute:: actual_kpoints</span>

<span class="sd">        List of actual kpoints, e.g.,</span>
<span class="sd">        [[0.25, 0.125, 0.08333333], [-0.25, 0.125, 0.08333333],</span>
<span class="sd">        [0.25, 0.375, 0.08333333], ....]</span>

<span class="sd">    .. attribute:: actual_kpoints_weights</span>

<span class="sd">        List of kpoint weights, E.g.,</span>
<span class="sd">        [0.04166667, 0.04166667, 0.04166667, 0.04166667, 0.04166667, ....]</span>

<span class="sd">    .. attribute:: atomic_symbols</span>

<span class="sd">        List of atomic symbols, e.g., [&quot;Li&quot;, &quot;Fe&quot;, &quot;Fe&quot;, &quot;P&quot;, &quot;P&quot;, &quot;P&quot;]</span>

<span class="sd">    .. attribute:: potcar_symbols</span>

<span class="sd">        List of POTCAR symbols. e.g.,</span>
<span class="sd">        [&quot;PAW_PBE Li 17Jan2003&quot;, &quot;PAW_PBE Fe 06Sep2000&quot;, ..]</span>

<span class="sd">    Author: Shyue Ping Ong</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">ionic_step_skip</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">ionic_step_offset</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">parse_dos</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                 <span class="n">parse_eigen</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">parse_projected_eigen</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">parse_potcar_file</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">occu_tol</span><span class="o">=</span><span class="mf">1e-8</span><span class="p">,</span>
                 <span class="n">exception_on_bad_xml</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename to parse</span>
<span class="sd">            ionic_step_skip (int): If ionic_step_skip is a number &gt; 1,</span>
<span class="sd">                only every ionic_step_skip ionic steps will be read for</span>
<span class="sd">                structure and energies. This is very useful if you are parsing</span>
<span class="sd">                very large vasprun.xml files and you are not interested in every</span>
<span class="sd">                single ionic step. Note that the final energies may not be the</span>
<span class="sd">                actual final energy in the vasprun.</span>
<span class="sd">            ionic_step_offset (int): Used together with ionic_step_skip. If set,</span>
<span class="sd">                the first ionic step read will be offset by the amount of</span>
<span class="sd">                ionic_step_offset. For example, if you want to start reading</span>
<span class="sd">                every 10th structure but only from the 3rd structure onwards,</span>
<span class="sd">                set ionic_step_skip to 10 and ionic_step_offset to 3. Main use</span>
<span class="sd">                case is when doing statistical structure analysis with</span>
<span class="sd">                extremely long time scale multiple VASP calculations of</span>
<span class="sd">                varying numbers of steps.</span>
<span class="sd">            parse_dos (bool): Whether to parse the dos. Defaults to True. Set</span>
<span class="sd">                to False to shave off significant time from the parsing if you</span>
<span class="sd">                are not interested in getting those data.</span>
<span class="sd">            parse_eigen (bool): Whether to parse the eigenvalues. Defaults to</span>
<span class="sd">                True. Set to False to shave off significant time from the</span>
<span class="sd">                parsing if you are not interested in getting those data.</span>
<span class="sd">            parse_projected_eigen (bool): Whether to parse the projected</span>
<span class="sd">                eigenvalues. Defaults to False. Set to True to obtain projected</span>
<span class="sd">                eigenvalues. **Note that this can take an extreme amount of time</span>
<span class="sd">                and memory.** So use this wisely.</span>
<span class="sd">            parse_potcar_file (bool/str): Whether to parse the potcar file to read</span>
<span class="sd">                the potcar hashes for the potcar_spec attribute. Defaults to True,</span>
<span class="sd">                where no hashes will be determined and the potcar_spec dictionaries</span>
<span class="sd">                will read {&quot;symbol&quot;: ElSymbol, &quot;hash&quot;: None}. By Default, looks in</span>
<span class="sd">                the same directory as the vasprun.xml, with same extensions as</span>
<span class="sd">                 Vasprun.xml. If a string is provided, looks at that filepath.</span>
<span class="sd">            occu_tol (float): Sets the minimum tol for the determination of the</span>
<span class="sd">                vbm and cbm. Usually the default of 1e-8 works well enough,</span>
<span class="sd">                but there may be pathological cases.</span>
<span class="sd">            exception_on_bad_xml (bool): Whether to throw a ParseException if a</span>
<span class="sd">                malformed XML is detected. Default to True, which ensures only</span>
<span class="sd">                proper vasprun.xml are parsed. You can set to False if you want</span>
<span class="sd">                partial results (e.g., if you are monitoring a calculation during a</span>
<span class="sd">                run), but use the results with care. A warning is issued.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ionic_step_skip</span> <span class="o">=</span> <span class="n">ionic_step_skip</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ionic_step_offset</span> <span class="o">=</span> <span class="n">ionic_step_offset</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">occu_tol</span> <span class="o">=</span> <span class="n">occu_tol</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">exception_on_bad_xml</span> <span class="o">=</span> <span class="n">exception_on_bad_xml</span>

        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">ionic_step_skip</span> <span class="ow">or</span> <span class="n">ionic_step_offset</span><span class="p">:</span>
                <span class="c1"># remove parts of the xml file and parse the string</span>
                <span class="n">run</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
                <span class="n">steps</span> <span class="o">=</span> <span class="n">run</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;&lt;calculation&gt;&quot;</span><span class="p">)</span>
                <span class="c1"># The text before the first &lt;calculation&gt; is the preamble!</span>
                <span class="n">preamble</span> <span class="o">=</span> <span class="n">steps</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">nionic_steps</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">steps</span><span class="p">)</span>
                <span class="n">new_steps</span> <span class="o">=</span> <span class="n">steps</span><span class="p">[</span><span class="n">ionic_step_offset</span><span class="p">::</span><span class="nb">int</span><span class="p">(</span><span class="n">ionic_step_skip</span><span class="p">)]</span>
                <span class="c1"># add the tailing informat in the last step from the run</span>
                <span class="n">to_parse</span> <span class="o">=</span> <span class="s2">&quot;&lt;calculation&gt;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">new_steps</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="n">new_steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
                    <span class="n">to_parse</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&lt;calculation&gt;</span><span class="si">{}{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">preamble</span><span class="p">,</span> <span class="n">to_parse</span><span class="p">,</span>
                        <span class="n">steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;&lt;/calculation&gt;&quot;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">to_parse</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">&lt;calculation&gt;</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">preamble</span><span class="p">,</span> <span class="n">to_parse</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_parse</span><span class="p">(</span><span class="n">StringIO</span><span class="p">(</span><span class="n">to_parse</span><span class="p">),</span> <span class="n">parse_dos</span><span class="o">=</span><span class="n">parse_dos</span><span class="p">,</span>
                            <span class="n">parse_eigen</span><span class="o">=</span><span class="n">parse_eigen</span><span class="p">,</span>
                            <span class="n">parse_projected_eigen</span><span class="o">=</span><span class="n">parse_projected_eigen</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_parse</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">parse_dos</span><span class="o">=</span><span class="n">parse_dos</span><span class="p">,</span> <span class="n">parse_eigen</span><span class="o">=</span><span class="n">parse_eigen</span><span class="p">,</span>
                            <span class="n">parse_projected_eigen</span><span class="o">=</span><span class="n">parse_projected_eigen</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">nionic_steps</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">parse_potcar_file</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">update_potcar_spec</span><span class="p">(</span><span class="n">parse_potcar_file</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">update_charge_from_potcar</span><span class="p">(</span><span class="n">parse_potcar_file</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;ALGO&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="o">!=</span> <span class="s2">&quot;BSE&quot;</span> <span class="ow">and</span> <span class="p">(</span><span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">converged</span><span class="p">):</span>
            <span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is an unconverged VASP run.</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">filename</span>
            <span class="n">msg</span> <span class="o">+=</span> <span class="s2">&quot;Electronic convergence reached: </span><span class="si">%s</span><span class="s2">.</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> \
                   <span class="bp">self</span><span class="o">.</span><span class="n">converged_electronic</span>
            <span class="n">msg</span> <span class="o">+=</span> <span class="s2">&quot;Ionic convergence reached: </span><span class="si">%s</span><span class="s2">.&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">converged_ionic</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">UnconvergedVASPWarning</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stream</span><span class="p">,</span> <span class="n">parse_dos</span><span class="p">,</span> <span class="n">parse_eigen</span><span class="p">,</span> <span class="n">parse_projected_eigen</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">other_dielectric</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">ionic_steps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">parsed_header</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">event</span><span class="p">,</span> <span class="n">elem</span> <span class="ow">in</span> <span class="n">ET</span><span class="o">.</span><span class="n">iterparse</span><span class="p">(</span><span class="n">stream</span><span class="p">):</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="n">tag</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">parsed_header</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;generator&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">generator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_params</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;incar&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">incar</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_params</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;kpoints&quot;</span><span class="p">:</span>
                        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;kpoints&#39;</span><span class="p">):</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints_weights</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_kpoints</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;parameters&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_params</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;structure&quot;</span> <span class="ow">and</span> <span class="n">elem</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;initialpos&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">initial_structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_structure</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;atominfo&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">atomic_symbols</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_atominfo</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">potcar_spec</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">&quot;titel&quot;</span><span class="p">:</span> <span class="n">p</span><span class="p">,</span>
                                             <span class="s2">&quot;hash&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span> <span class="k">for</span>
                                            <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;calculation&quot;</span><span class="p">:</span>
                    <span class="n">parsed_header</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LCHIMAG&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
                        <span class="n">ionic_steps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_parse_calculation</span><span class="p">(</span><span class="n">elem</span><span class="p">))</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">ionic_steps</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_parse_chemical_shielding_calculation</span><span class="p">(</span><span class="n">elem</span><span class="p">))</span>
                <span class="k">elif</span> <span class="n">parse_dos</span> <span class="ow">and</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;dos&quot;</span><span class="p">:</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">tdos</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">idos</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_dos</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tdos</span><span class="o">.</span><span class="n">efermi</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">dos_has_errors</span> <span class="o">=</span> <span class="kc">False</span>
                    <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">dos_has_errors</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">elif</span> <span class="n">parse_eigen</span> <span class="ow">and</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;eigenvalues&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_eigen</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">parse_projected_eigen</span> <span class="ow">and</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;projected&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_projected_eigen</span><span class="p">(</span>
                        <span class="n">elem</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;dielectricfunction&quot;</span><span class="p">:</span>
                    <span class="k">if</span> <span class="p">(</span><span class="s2">&quot;comment&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">attrib</span> <span class="ow">or</span>
                            <span class="n">elem</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">]</span> <span class="o">==</span>
                            <span class="s2">&quot;INVERSE MACROSCOPIC DIELECTRIC TENSOR (including &quot;</span>
                            <span class="s2">&quot;local field effects in RPA (Hartree))&quot;</span><span class="p">):</span>
                        <span class="k">if</span> <span class="s1">&#39;density&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s1">&#39;density&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_diel</span><span class="p">(</span>
                                <span class="n">elem</span><span class="p">)</span>
                        <span class="k">elif</span> <span class="s1">&#39;velocity&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">:</span>
                            <span class="c1"># &quot;velocity-velocity&quot; is also named</span>
                            <span class="c1"># &quot;current-current&quot; in OUTCAR</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s1">&#39;velocity&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_diel</span><span class="p">(</span>
                                <span class="n">elem</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span>
                                <span class="s1">&#39;This vasprun.xml has &gt;2 unlabelled dielectric &#39;</span>
                                <span class="s1">&#39;functions&#39;</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">comment</span> <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">]</span>
                        <span class="c1"># VASP 6+ has labels for the density and current</span>
                        <span class="c1"># derived dielectric constants</span>
                        <span class="k">if</span> <span class="n">comment</span> <span class="o">==</span> <span class="s2">&quot;density-density&quot;</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s2">&quot;density&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_diel</span><span class="p">(</span>
                                <span class="n">elem</span><span class="p">)</span>
                        <span class="k">elif</span> <span class="n">comment</span> <span class="o">==</span> <span class="s2">&quot;current-current&quot;</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s2">&quot;velocity&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_diel</span><span class="p">(</span>
                                <span class="n">elem</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">other_dielectric</span><span class="p">[</span><span class="n">comment</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_diel</span><span class="p">(</span>
                                <span class="n">elem</span><span class="p">)</span>

                <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;varray&quot;</span> <span class="ow">and</span> <span class="n">elem</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;opticaltransitions&#39;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">optical_transition</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">_parse_varray</span><span class="p">(</span><span class="n">elem</span><span class="p">))</span>
                <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;structure&quot;</span> <span class="ow">and</span> <span class="n">elem</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span> <span class="o">==</span> \
                        <span class="s2">&quot;finalpos&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_structure</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;dynmat&quot;</span><span class="p">:</span>
                    <span class="n">hessian</span><span class="p">,</span> <span class="n">eigenvalues</span><span class="p">,</span> <span class="n">eigenvectors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_dynmat</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="n">natoms</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atomic_symbols</span><span class="p">)</span>
                    <span class="n">hessian</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">hessian</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">force_constants</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">natoms</span><span class="p">,</span> <span class="n">natoms</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;double&#39;</span><span class="p">)</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">natoms</span><span class="p">):</span>
                        <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">natoms</span><span class="p">):</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">force_constants</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">hessian</span><span class="p">[</span><span class="n">i</span> <span class="o">*</span> <span class="mi">3</span><span class="p">:(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">3</span><span class="p">,</span> <span class="n">j</span> <span class="o">*</span> <span class="mi">3</span><span class="p">:(</span><span class="n">j</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">3</span><span class="p">]</span>
                    <span class="n">phonon_eigenvectors</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">for</span> <span class="n">ev</span> <span class="ow">in</span> <span class="n">eigenvectors</span><span class="p">:</span>
                        <span class="n">phonon_eigenvectors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">natoms</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">normalmode_eigenvals</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">eigenvalues</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">normalmode_eigenvecs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">phonon_eigenvectors</span><span class="p">)</span>
        <span class="k">except</span> <span class="n">ET</span><span class="o">.</span><span class="n">ParseError</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">exception_on_bad_xml</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">ex</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                    <span class="s2">&quot;XML is malformed. Parsing has stopped but partial data&quot;</span>
                    <span class="s2">&quot;is available.&quot;</span><span class="p">,</span> <span class="ne">UserWarning</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span> <span class="o">=</span> <span class="n">ionic_steps</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">vasp_version</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">structures</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns:</span>
<span class="sd">             List of Structure objects for the structure at each ionic step.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">step</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">epsilon_static</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Property only available for DFPT calculations.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The static part of the dielectric constant. Present when it&#39;s a DFPT run</span>
<span class="sd">            (LEPSILON=TRUE)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;epsilon&quot;</span><span class="p">,</span> <span class="p">[])</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">epsilon_static_wolfe</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Property only available for DFPT calculations.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The static part of the dielectric constant without any local field</span>
<span class="sd">            effects. Present when it&#39;s a DFPT run (LEPSILON=TRUE)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;epsilon_rpa&quot;</span><span class="p">,</span> <span class="p">[])</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">epsilon_ionic</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Property only available for DFPT calculations and when IBRION=5, 6, 7 or 8.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The ionic part of the static dielectric constant. Present when it&#39;s a</span>
<span class="sd">            DFPT run (LEPSILON=TRUE) and IBRION=5, 6, 7 or 8</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;epsilon_ion&quot;</span><span class="p">,</span> <span class="p">[])</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">dielectric</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns:</span>
<span class="sd">            The real and imaginary part of the dielectric constant (e.g., computed</span>
<span class="sd">            by RPA) in function of the energy (frequency). Optical properties (e.g.</span>
<span class="sd">            absorption coefficient) can be obtained through this.</span>
<span class="sd">            The data is given as a tuple of 3 values containing each of them</span>
<span class="sd">            the energy, the real part tensor, and the imaginary part tensor</span>
<span class="sd">            ([energies],[[real_partxx,real_partyy,real_partzz,real_partxy,</span>
<span class="sd">            real_partyz,real_partxz]],[[imag_partxx,imag_partyy,imag_partzz,</span>
<span class="sd">            imag_partxy, imag_partyz, imag_partxz]])</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s1">&#39;density&#39;</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">optical_absorption_coeff</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculate the optical absorption coefficient</span>
<span class="sd">        from the dielectric constants. Note that this method is only</span>
<span class="sd">        implemented for optical properties calculated with GGA and BSE.</span>
<span class="sd">        Returns:</span>
<span class="sd">        optical absorption coefficient in list</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s2">&quot;density&quot;</span><span class="p">]:</span>
            <span class="n">real_avg</span> <span class="o">=</span> <span class="p">[</span><span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s2">&quot;density&quot;</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="mi">3</span><span class="p">])</span> <span class="o">/</span> <span class="mi">3</span>
                        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s2">&quot;density&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">]))]</span>
            <span class="n">imag_avg</span> <span class="o">=</span> <span class="p">[</span><span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s2">&quot;density&quot;</span><span class="p">][</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="mi">3</span><span class="p">])</span> <span class="o">/</span> <span class="mi">3</span>
                        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s2">&quot;density&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">]))]</span>

            <span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">freq</span><span class="p">,</span> <span class="n">real</span><span class="p">,</span> <span class="n">imag</span><span class="p">):</span>
                <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">                The optical absorption coefficient calculated in terms of</span>
<span class="sd">                equation</span>
<span class="sd">                &quot;&quot;&quot;</span>
                <span class="n">hbar</span> <span class="o">=</span> <span class="mf">6.582119514e-16</span>  <span class="c1"># eV/K</span>
                <span class="n">coeff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">real</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">imag</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-</span> <span class="n">real</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">/</span> <span class="n">hbar</span> <span class="o">*</span> <span class="n">freq</span>
                <span class="k">return</span> <span class="n">coeff</span>

            <span class="n">absorption_coeff</span> <span class="o">=</span> <span class="p">[</span><span class="n">f</span><span class="p">(</span><span class="n">freq</span><span class="p">,</span> <span class="n">real</span><span class="p">,</span> <span class="n">imag</span><span class="p">)</span> <span class="k">for</span> <span class="n">freq</span><span class="p">,</span> <span class="n">real</span><span class="p">,</span> <span class="n">imag</span> <span class="ow">in</span>
                                <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dielectric_data</span><span class="p">[</span><span class="s2">&quot;density&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">real_avg</span><span class="p">,</span> <span class="n">imag_avg</span><span class="p">)]</span>
        <span class="k">return</span> <span class="n">absorption_coeff</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">converged_electronic</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns:</span>
<span class="sd">            True if electronic step convergence has been reached in the final</span>
<span class="sd">            ionic step</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">final_esteps</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="s1">&#39;LEPSILON&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="p">[</span><span class="s1">&#39;LEPSILON&#39;</span><span class="p">]:</span>
            <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="n">to_check</span> <span class="o">=</span> <span class="nb">set</span><span class="p">([</span><span class="s1">&#39;e_wo_entrp&#39;</span><span class="p">,</span> <span class="s1">&#39;e_fr_energy&#39;</span><span class="p">,</span> <span class="s1">&#39;e_0_energy&#39;</span><span class="p">])</span>
            <span class="k">while</span> <span class="nb">set</span><span class="p">(</span><span class="n">final_esteps</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span> <span class="o">==</span> <span class="n">to_check</span><span class="p">:</span>
                <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">return</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">[</span><span class="s2">&quot;NELM&quot;</span><span class="p">]</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">final_esteps</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">[</span><span class="s2">&quot;NELM&quot;</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">converged_ionic</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns:</span>
<span class="sd">            True if ionic step convergence has been reached, i.e. that vasp</span>
<span class="sd">            exited before reaching the max ionic steps for a relaxation run</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">nsw</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;NSW&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">nsw</span> <span class="o">&lt;=</span> <span class="mi">1</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">nsw</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">converged</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns:</span>
<span class="sd">            True if a relaxation run is converged both ionically and</span>
<span class="sd">            electronically.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">converged_electronic</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">converged_ionic</span>

    <span class="nd">@property</span>  <span class="c1"># type: ignore</span>
    <span class="nd">@unitized</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">final_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Final energy from the vasp run.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">final_istep</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">final_istep</span><span class="p">[</span><span class="s2">&quot;e_wo_entrp&quot;</span><span class="p">]</span> <span class="o">!=</span> <span class="n">final_istep</span><span class="p">[</span><span class="s1">&#39;electronic_steps&#39;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;e_0_energy&quot;</span><span class="p">]:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Final e_wo_entrp differs from the final &quot;</span>
                              <span class="s2">&quot;electronic step. VASP may have included some &quot;</span>
                              <span class="s2">&quot;corrections, e.g., vdw. Vasprun will return &quot;</span>
                              <span class="s2">&quot;the final e_wo_entrp, i.e., including &quot;</span>
                              <span class="s2">&quot;corrections in such instances.&quot;</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">final_istep</span><span class="p">[</span><span class="s2">&quot;e_wo_entrp&quot;</span><span class="p">]</span>
            <span class="k">return</span> <span class="n">final_istep</span><span class="p">[</span><span class="s1">&#39;electronic_steps&#39;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;e_0_energy&quot;</span><span class="p">]</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">IndexError</span><span class="p">,</span> <span class="ne">KeyError</span><span class="p">):</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Calculation does not have a total energy. &quot;</span>
                          <span class="s2">&quot;Possibly a GW or similar kind of run. A value of &quot;</span>
                          <span class="s2">&quot;infinity is returned.&quot;</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="s1">&#39;inf&#39;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">complete_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        A complete dos object which incorporates the total dos and all</span>
<span class="sd">        projected dos.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">final_struct</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span>
        <span class="n">pdoss</span> <span class="o">=</span> <span class="p">{</span><span class="n">final_struct</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span> <span class="n">pdos</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="p">)}</span>
        <span class="k">return</span> <span class="n">CompleteDos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tdos</span><span class="p">,</span> <span class="n">pdoss</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">hubbards</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Hubbard U values used if a vasprun is a GGA+U run. {} otherwise.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
        <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">]</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LDAU&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">{}</span>
        <span class="n">us</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LDAUU&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LDAUU&quot;</span><span class="p">))</span>
        <span class="n">js</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LDAUJ&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LDAUJ&quot;</span><span class="p">))</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">js</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">us</span><span class="p">):</span>
            <span class="n">js</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">us</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">us</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">symbols</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">{</span><span class="n">symbols</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span> <span class="n">us</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="n">js</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">symbols</span><span class="p">))}</span>
        <span class="k">elif</span> <span class="nb">sum</span><span class="p">(</span><span class="n">us</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="nb">sum</span><span class="p">(</span><span class="n">js</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">VaspParserError</span><span class="p">(</span><span class="s2">&quot;Length of U value parameters and atomic &quot;</span>
                                  <span class="s2">&quot;symbols are mismatched&quot;</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">run_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the run type. Currently supports LDA, GGA, vdW-DF and HF calcs.</span>

<span class="sd">        TODO: Fix for other functional types like PW91, other vdW types, etc.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">GGA_TYPES</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;RE&quot;</span><span class="p">:</span> <span class="s2">&quot;revPBE&quot;</span><span class="p">,</span> <span class="s2">&quot;PE&quot;</span><span class="p">:</span> <span class="s2">&quot;PBE&quot;</span><span class="p">,</span> <span class="s2">&quot;PS&quot;</span><span class="p">:</span> <span class="s2">&quot;PBESol&quot;</span><span class="p">,</span> <span class="s2">&quot;RP&quot;</span><span class="p">:</span> <span class="s2">&quot;RevPBE+PADE&quot;</span><span class="p">,</span> <span class="s2">&quot;AM&quot;</span><span class="p">:</span> <span class="s2">&quot;AM05&quot;</span><span class="p">,</span> <span class="s2">&quot;OR&quot;</span><span class="p">:</span> <span class="s2">&quot;optPBE&quot;</span><span class="p">,</span>
                     <span class="s2">&quot;BO&quot;</span><span class="p">:</span> <span class="s2">&quot;optB88&quot;</span><span class="p">,</span> <span class="s2">&quot;MK&quot;</span><span class="p">:</span> <span class="s2">&quot;optB86b&quot;</span><span class="p">,</span> <span class="s2">&quot;--&quot;</span><span class="p">:</span> <span class="s2">&quot;GGA&quot;</span><span class="p">}</span>

        <span class="n">METAGGA_TYPES</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;TPSS&quot;</span><span class="p">:</span> <span class="s2">&quot;TPSS&quot;</span><span class="p">,</span> <span class="s2">&quot;RTPSS&quot;</span><span class="p">:</span> <span class="s2">&quot;revTPSS&quot;</span><span class="p">,</span> <span class="s2">&quot;M06L&quot;</span><span class="p">:</span> <span class="s2">&quot;M06-L&quot;</span><span class="p">,</span> <span class="s2">&quot;MBJ&quot;</span><span class="p">:</span> <span class="s2">&quot;modified Becke-Johnson&quot;</span><span class="p">,</span>
                         <span class="s2">&quot;SCAN&quot;</span><span class="p">:</span> <span class="s2">&quot;SCAN&quot;</span><span class="p">,</span> <span class="s2">&quot;MS0&quot;</span><span class="p">:</span> <span class="s2">&quot;MadeSimple0&quot;</span><span class="p">,</span> <span class="s2">&quot;MS1&quot;</span><span class="p">:</span> <span class="s2">&quot;MadeSimple1&quot;</span><span class="p">,</span> <span class="s2">&quot;MS2&quot;</span><span class="p">:</span> <span class="s2">&quot;MadeSimple2&quot;</span><span class="p">}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;AEXX&quot;</span><span class="p">,</span> <span class="mf">1.00</span><span class="p">)</span> <span class="o">==</span> <span class="mf">1.00</span><span class="p">:</span>
            <span class="n">rt</span> <span class="o">=</span> <span class="s2">&quot;HF&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;HFSCREEN&quot;</span><span class="p">,</span> <span class="mf">0.30</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0.30</span><span class="p">:</span>
            <span class="n">rt</span> <span class="o">=</span> <span class="s2">&quot;HSE03&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;HFSCREEN&quot;</span><span class="p">,</span> <span class="mf">0.20</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0.20</span><span class="p">:</span>
            <span class="n">rt</span> <span class="o">=</span> <span class="s2">&quot;HSE06&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;AEXX&quot;</span><span class="p">,</span> <span class="mf">0.20</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0.20</span><span class="p">:</span>
            <span class="n">rt</span> <span class="o">=</span> <span class="s2">&quot;B3LYP&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LHFCALC&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">):</span>
            <span class="n">rt</span> <span class="o">=</span> <span class="s2">&quot;PBEO or other Hybrid Functional&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LUSE_VDW&quot;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;METAGGA&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="n">METAGGA_TYPES</span><span class="p">:</span>
                <span class="n">rt</span> <span class="o">=</span> <span class="n">METAGGA_TYPES</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;METAGGA&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()]</span> <span class="o">+</span> <span class="s2">&quot;+rVV10&quot;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">rt</span> <span class="o">=</span> <span class="n">GGA_TYPES</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;GGA&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()]</span> <span class="o">+</span> <span class="s2">&quot;+rVV10&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;METAGGA&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="n">METAGGA_TYPES</span><span class="p">:</span>
            <span class="n">rt</span> <span class="o">=</span> <span class="n">METAGGA_TYPES</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;METAGGA&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()]</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_hubbard</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LDAU&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">):</span>
                <span class="n">rt</span> <span class="o">+=</span> <span class="s2">&quot;+U&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;PAW&#39;</span><span class="p">:</span>
            <span class="n">rt</span> <span class="o">=</span> <span class="s2">&quot;LDA&quot;</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;GGA&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="n">GGA_TYPES</span><span class="p">:</span>
            <span class="n">rt</span> <span class="o">=</span> <span class="n">GGA_TYPES</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;GGA&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()]</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_hubbard</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;LDAU&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">):</span>
                <span class="n">rt</span> <span class="o">+=</span> <span class="s2">&quot;+U&quot;</span>
        <span class="k">return</span> <span class="n">rt</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_hubbard</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        True if run is a DFT+U run.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">hubbards</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">hubbards</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mf">1e-8</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_spin</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        True if run is spin-polarized.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;ISPIN&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span>

<div class="viewcode-block" id="Vasprun.get_computed_entry"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Vasprun.get_computed_entry">[docs]</a>    <span class="k">def</span> <span class="nf">get_computed_entry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inc_structure</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">parameters</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                           <span class="n">data</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a ComputedStructureEntry from the vasprun.</span>

<span class="sd">        Args:</span>
<span class="sd">            inc_structure (bool): Set to True if you want</span>
<span class="sd">                ComputedStructureEntries to be returned instead of</span>
<span class="sd">                ComputedEntries.</span>
<span class="sd">            parameters (list): Input parameters to include. It has to be one of</span>
<span class="sd">                the properties supported by the Vasprun object. If</span>
<span class="sd">                parameters is None, a default set of parameters that are</span>
<span class="sd">                necessary for typical post-processing will be set.</span>
<span class="sd">            data (list): Output data to include. Has to be one of the properties</span>
<span class="sd">                supported by the Vasprun object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            ComputedStructureEntry/ComputedEntry</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">param_names</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;is_hubbard&quot;</span><span class="p">,</span> <span class="s2">&quot;hubbards&quot;</span><span class="p">,</span> <span class="s2">&quot;potcar_symbols&quot;</span><span class="p">,</span>
                       <span class="s2">&quot;potcar_spec&quot;</span><span class="p">,</span> <span class="s2">&quot;run_type&quot;</span><span class="p">}</span>
        <span class="k">if</span> <span class="n">parameters</span><span class="p">:</span>
            <span class="n">param_names</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">parameters</span><span class="p">)</span>
        <span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="n">p</span><span class="p">:</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">param_names</span><span class="p">}</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="n">p</span><span class="p">:</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">data</span><span class="p">}</span> <span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="p">{}</span>

        <span class="k">if</span> <span class="n">inc_structure</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">ComputedStructureEntry</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="p">,</span>
                                          <span class="bp">self</span><span class="o">.</span><span class="n">final_energy</span><span class="p">,</span> <span class="n">parameters</span><span class="o">=</span><span class="n">params</span><span class="p">,</span>
                                          <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">ComputedEntry</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">composition</span><span class="p">,</span>
                                 <span class="bp">self</span><span class="o">.</span><span class="n">final_energy</span><span class="p">,</span> <span class="n">parameters</span><span class="o">=</span><span class="n">params</span><span class="p">,</span>
                                 <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span></div>

<div class="viewcode-block" id="Vasprun.get_band_structure"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Vasprun.get_band_structure">[docs]</a>    <span class="k">def</span> <span class="nf">get_band_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kpoints_filename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">efermi</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                           <span class="n">line_mode</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">force_hybrid_mode</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the band structure as a BandStructure object</span>

<span class="sd">        Args:</span>
<span class="sd">            kpoints_filename (str): Full path of the KPOINTS file from which</span>
<span class="sd">                the band structure is generated.</span>
<span class="sd">                If none is provided, the code will try to intelligently</span>
<span class="sd">                determine the appropriate KPOINTS file by substituting the</span>
<span class="sd">                filename of the vasprun.xml with KPOINTS.</span>
<span class="sd">                The latter is the default behavior.</span>
<span class="sd">            efermi (float): If you want to specify manually the fermi energy</span>
<span class="sd">                this is where you should do it. By default, the None value</span>
<span class="sd">                means the code will get it from the vasprun.</span>
<span class="sd">            line_mode (bool): Force the band structure to be considered as</span>
<span class="sd">                a run along symmetry lines.</span>
<span class="sd">            force_hybrid_mode (bool): Makes it possible to read in self-consistent band structure calculations for</span>
<span class="sd">                every type of functional</span>

<span class="sd">        Returns:</span>
<span class="sd">            a BandStructure object (or more specifically a</span>
<span class="sd">            BandStructureSymmLine object if the run is detected to be a run</span>
<span class="sd">            along symmetry lines)</span>

<span class="sd">            Two types of runs along symmetry lines are accepted: non-sc with</span>
<span class="sd">            Line-Mode in the KPOINT file or hybrid, self-consistent with a</span>
<span class="sd">            uniform grid+a few kpoints along symmetry lines (explicit KPOINTS</span>
<span class="sd">            file) (it&#39;s not possible to run a non-sc band structure with hybrid</span>
<span class="sd">            functionals). The explicit KPOINTS file needs to have data on the</span>
<span class="sd">            kpoint label as commentary.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">kpoints_filename</span><span class="p">:</span>
            <span class="n">kpoints_filename</span> <span class="o">=</span> <span class="n">zpath</span><span class="p">(</span>
                <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">),</span> <span class="s1">&#39;KPOINTS&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">kpoints_filename</span><span class="p">)</span> <span class="ow">and</span> <span class="n">line_mode</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">VaspParserError</span><span class="p">(</span><span class="s1">&#39;KPOINTS needed to obtain band structure &#39;</span>
                                  <span class="s1">&#39;along symmetry lines.&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">efermi</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">efermi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span>

        <span class="n">kpoint_file</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">kpoints_filename</span><span class="p">):</span>
            <span class="n">kpoint_file</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">kpoints_filename</span><span class="p">)</span>
        <span class="n">lattice_new</span> <span class="o">=</span> <span class="n">Lattice</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">reciprocal_lattice</span><span class="o">.</span><span class="n">matrix</span><span class="p">)</span>

        <span class="n">kpoints</span> <span class="o">=</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                   <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">))]</span>

        <span class="n">p_eigenvals</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
        <span class="n">eigenvals</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>

        <span class="n">nkpts</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">kpoints</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="n">eigenvals</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span><span class="p">[:,</span> <span class="p">:,</span> <span class="mi">0</span><span class="p">]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span><span class="p">:</span>
                <span class="n">peigen</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span>
                <span class="c1"># Original axes for self.projected_eigenvalues are kpoints,</span>
                <span class="c1"># band, ion, orb.</span>
                <span class="c1"># For BS input, we need band, kpoints, orb, ion.</span>
                <span class="n">peigen</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">peigen</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>  <span class="c1"># Swap kpoint and band axes</span>
                <span class="n">peigen</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">swapaxes</span><span class="p">(</span><span class="n">peigen</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>  <span class="c1"># Swap ion and orb axes</span>

                <span class="n">p_eigenvals</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">peigen</span>
                <span class="c1"># for b in range(min_eigenvalues):</span>
                <span class="c1">#     p_eigenvals[spin].append(</span>
                <span class="c1">#         [{Orbital(orb): v for orb, v in enumerate(peigen[b, k])}</span>
                <span class="c1">#          for k in range(nkpts)])</span>

        <span class="c1"># check if we have an hybrid band structure computation</span>
        <span class="c1"># for this we look at the presence of the LHFCALC tag</span>
        <span class="n">hybrid_band</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;LHFCALC&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span> <span class="ow">or</span> \
                <span class="mf">0.</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints_weights</span><span class="p">:</span>
            <span class="n">hybrid_band</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="k">if</span> <span class="n">kpoint_file</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">kpoint_file</span><span class="o">.</span><span class="n">style</span> <span class="o">==</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Line_mode</span><span class="p">:</span>
                <span class="n">line_mode</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="k">if</span> <span class="n">line_mode</span><span class="p">:</span>
            <span class="n">labels_dict</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="n">hybrid_band</span> <span class="ow">or</span> <span class="n">force_hybrid_mode</span><span class="p">:</span>
                <span class="n">start_bs_index</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">)):</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints_weights</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">:</span>
                        <span class="n">start_bs_index</span> <span class="o">=</span> <span class="n">i</span>
                        <span class="k">break</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">start_bs_index</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">kpoint_file</span><span class="o">.</span><span class="n">kpts</span><span class="p">)):</span>
                    <span class="k">if</span> <span class="n">kpoint_file</span><span class="o">.</span><span class="n">labels</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="n">labels_dict</span><span class="p">[</span><span class="n">kpoint_file</span><span class="o">.</span><span class="n">labels</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="o">=</span> \
                            <span class="n">kpoint_file</span><span class="o">.</span><span class="n">kpts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="c1"># remake the data only considering line band structure k-points</span>
                <span class="c1"># (weight = 0.0 kpoints)</span>
                <span class="n">nbands</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">])</span>
                <span class="n">kpoints</span> <span class="o">=</span> <span class="n">kpoints</span><span class="p">[</span><span class="n">start_bs_index</span><span class="p">:</span><span class="n">nkpts</span><span class="p">]</span>
                <span class="n">up_eigen</span> <span class="o">=</span> <span class="p">[</span><span class="n">eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">start_bs_index</span><span class="p">:</span><span class="n">nkpts</span><span class="p">]</span>
                            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbands</span><span class="p">)]</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span><span class="p">:</span>
                    <span class="n">p_eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">p_eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">i</span><span class="p">][</span>
                                            <span class="n">start_bs_index</span><span class="p">:</span><span class="n">nkpts</span><span class="p">]</span>
                                            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbands</span><span class="p">)]</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin</span><span class="p">:</span>
                    <span class="n">down_eigen</span> <span class="o">=</span> <span class="p">[</span><span class="n">eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][</span><span class="n">i</span><span class="p">][</span><span class="n">start_bs_index</span><span class="p">:</span><span class="n">nkpts</span><span class="p">]</span>
                                  <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbands</span><span class="p">)]</span>
                    <span class="n">eigenvals</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="n">up_eigen</span><span class="p">,</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">:</span> <span class="n">down_eigen</span><span class="p">}</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span><span class="p">:</span>
                        <span class="n">p_eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">p_eigenvals</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][</span><span class="n">i</span><span class="p">][</span>
                                                  <span class="n">start_bs_index</span><span class="p">:</span><span class="n">nkpts</span><span class="p">]</span>
                                                  <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbands</span><span class="p">)]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">eigenvals</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="n">up_eigen</span><span class="p">}</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="s1">&#39;&#39;</span> <span class="ow">in</span> <span class="n">kpoint_file</span><span class="o">.</span><span class="n">labels</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;A band structure along symmetry lines &quot;</span>
                                    <span class="s2">&quot;requires a label for each kpoint. &quot;</span>
                                    <span class="s2">&quot;Check your KPOINTS file&quot;</span><span class="p">)</span>
                <span class="n">labels_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">kpoint_file</span><span class="o">.</span><span class="n">labels</span><span class="p">,</span> <span class="n">kpoint_file</span><span class="o">.</span><span class="n">kpts</span><span class="p">))</span>
                <span class="n">labels_dict</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">BandStructureSymmLine</span><span class="p">(</span><span class="n">kpoints</span><span class="p">,</span> <span class="n">eigenvals</span><span class="p">,</span> <span class="n">lattice_new</span><span class="p">,</span>
                                         <span class="n">efermi</span><span class="p">,</span> <span class="n">labels_dict</span><span class="p">,</span>
                                         <span class="n">structure</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="p">,</span>
                                         <span class="n">projections</span><span class="o">=</span><span class="n">p_eigenvals</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">BandStructure</span><span class="p">(</span><span class="n">kpoints</span><span class="p">,</span> <span class="n">eigenvals</span><span class="p">,</span> <span class="n">lattice_new</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span>
                                 <span class="n">structure</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="p">,</span>
                                 <span class="n">projections</span><span class="o">=</span><span class="n">p_eigenvals</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">eigenvalue_band_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Band properties from the eigenvalues as a tuple,</span>
<span class="sd">        (band gap, cbm, vbm, is_band_gap_direct).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">vbm</span> <span class="o">=</span> <span class="o">-</span><span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>
        <span class="n">vbm_kpoint</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">cbm</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>
        <span class="n">cbm_kpoint</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
                <span class="k">for</span> <span class="p">(</span><span class="n">eigenval</span><span class="p">,</span> <span class="n">occu</span><span class="p">)</span> <span class="ow">in</span> <span class="n">val</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">occu</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">occu_tol</span> <span class="ow">and</span> <span class="n">eigenval</span> <span class="o">&gt;</span> <span class="n">vbm</span><span class="p">:</span>
                        <span class="n">vbm</span> <span class="o">=</span> <span class="n">eigenval</span>
                        <span class="n">vbm_kpoint</span> <span class="o">=</span> <span class="n">k</span>
                    <span class="k">elif</span> <span class="n">occu</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">occu_tol</span> <span class="ow">and</span> <span class="n">eigenval</span> <span class="o">&lt;</span> <span class="n">cbm</span><span class="p">:</span>
                        <span class="n">cbm</span> <span class="o">=</span> <span class="n">eigenval</span>
                        <span class="n">cbm_kpoint</span> <span class="o">=</span> <span class="n">k</span>
        <span class="k">return</span> <span class="nb">max</span><span class="p">(</span><span class="n">cbm</span> <span class="o">-</span> <span class="n">vbm</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">cbm</span><span class="p">,</span> <span class="n">vbm</span><span class="p">,</span> <span class="n">vbm_kpoint</span> <span class="o">==</span> <span class="n">cbm_kpoint</span>

<div class="viewcode-block" id="Vasprun.get_potcars"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Vasprun.get_potcars">[docs]</a>    <span class="k">def</span> <span class="nf">get_potcars</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param path: Path to search for POTCARs</span>
<span class="sd">        :return: Potcar from path.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">get_potcar_in_path</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">fn</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">p</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">fn</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;POTCAR&#39;</span><span class="p">):</span>
                    <span class="n">pc</span> <span class="o">=</span> <span class="n">Potcar</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">fn</span><span class="p">))</span>
                    <span class="k">if</span> <span class="p">{</span><span class="n">d</span><span class="o">.</span><span class="n">header</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">pc</span><span class="p">}</span> <span class="o">==</span> \
                            <span class="p">{</span><span class="n">sym</span> <span class="k">for</span> <span class="n">sym</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">}:</span>
                        <span class="k">return</span> <span class="n">pc</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;No POTCAR file with matching TITEL fields&quot;</span>
                          <span class="s2">&quot; was found in </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">p</span><span class="p">)))</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">Path</span><span class="p">)):</span>
            <span class="n">path</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
            <span class="k">if</span> <span class="s2">&quot;POTCAR&quot;</span> <span class="ow">in</span> <span class="n">path</span><span class="p">:</span>
                <span class="n">potcar</span> <span class="o">=</span> <span class="n">Potcar</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
                <span class="k">if</span> <span class="p">{</span><span class="n">d</span><span class="o">.</span><span class="n">TITEL</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">potcar</span><span class="p">}</span> <span class="o">!=</span> \
                        <span class="p">{</span><span class="n">sym</span> <span class="k">for</span> <span class="n">sym</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">}:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Potcar TITELs do not match Vasprun&quot;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">potcar</span> <span class="o">=</span> <span class="n">get_potcar_in_path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="nb">bool</span><span class="p">)</span> <span class="ow">and</span> <span class="n">path</span><span class="p">:</span>
            <span class="n">potcar</span> <span class="o">=</span> <span class="n">get_potcar_in_path</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">potcar</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="n">potcar</span></div>

<div class="viewcode-block" id="Vasprun.get_trajectory"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Vasprun.get_trajectory">[docs]</a>    <span class="k">def</span> <span class="nf">get_trajectory</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This method returns a Trajectory object, which is an alternative</span>
<span class="sd">        representation of self.structures into a single object. Forces are</span>
<span class="sd">        added to the Trajectory as site properties.</span>

<span class="sd">        Returns: a Trajectory</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># required due to circular imports</span>
        <span class="c1"># TODO: fix pymatgen.core.trajectory so it does not load from io.vasp(!)</span>
        <span class="kn">from</span> <span class="nn">pymatgen.core.trajectory</span> <span class="kn">import</span> <span class="n">Trajectory</span>

        <span class="n">structs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">:</span>
            <span class="n">struct</span> <span class="o">=</span> <span class="n">step</span><span class="p">[</span><span class="s1">&#39;structure&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">struct</span><span class="o">.</span><span class="n">add_site_property</span><span class="p">(</span><span class="s1">&#39;forces&#39;</span><span class="p">,</span> <span class="n">step</span><span class="p">[</span><span class="s1">&#39;forces&#39;</span><span class="p">])</span>
            <span class="n">structs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">struct</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">Trajectory</span><span class="o">.</span><span class="n">from_structures</span><span class="p">(</span><span class="n">structs</span><span class="p">,</span> <span class="n">constant_lattice</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>

<div class="viewcode-block" id="Vasprun.update_potcar_spec"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Vasprun.update_potcar_spec">[docs]</a>    <span class="k">def</span> <span class="nf">update_potcar_spec</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :param path: Path to search for POTCARs</span>
<span class="sd">        :return: Potcar spec from path.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">potcar</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_potcars</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">potcar</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">potcar_spec</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">&quot;titel&quot;</span><span class="p">:</span> <span class="n">sym</span><span class="p">,</span> <span class="s2">&quot;hash&quot;</span><span class="p">:</span> <span class="n">ps</span><span class="o">.</span><span class="n">get_potcar_hash</span><span class="p">()}</span>
                                <span class="k">for</span> <span class="n">sym</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span>
                                <span class="k">for</span> <span class="n">ps</span> <span class="ow">in</span> <span class="n">potcar</span> <span class="k">if</span>
                                <span class="n">ps</span><span class="o">.</span><span class="n">symbol</span> <span class="o">==</span> <span class="n">sym</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]]</span></div>

<div class="viewcode-block" id="Vasprun.update_charge_from_potcar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Vasprun.update_charge_from_potcar">[docs]</a>    <span class="k">def</span> <span class="nf">update_charge_from_potcar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets the charge of a structure based on the POTCARs found.</span>

<span class="sd">        :param path: Path to search for POTCARs</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">potcar</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_potcars</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">potcar</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;ALGO&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;GW0&quot;</span><span class="p">,</span> <span class="s2">&quot;G0W0&quot;</span><span class="p">,</span> <span class="s2">&quot;GW&quot;</span><span class="p">,</span> <span class="s2">&quot;BSE&quot;</span><span class="p">]:</span>
            <span class="n">nelect</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">[</span><span class="s2">&quot;NELECT&quot;</span><span class="p">]</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">potcar</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">initial_structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">element_composition</span><span class="p">):</span>
                <span class="n">potcar_nelect</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">initial_structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">element_composition</span><span class="p">[</span><span class="n">ps</span><span class="o">.</span><span class="n">element</span><span class="p">]</span> <span class="o">*</span> <span class="n">ps</span><span class="o">.</span><span class="n">ZVAL</span>
                    <span class="k">for</span> <span class="n">ps</span> <span class="ow">in</span> <span class="n">potcar</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">nums</span> <span class="o">=</span> <span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">g</span><span class="p">))</span> <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">g</span> <span class="ow">in</span>
                        <span class="n">itertools</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atomic_symbols</span><span class="p">)]</span>
                <span class="n">potcar_nelect</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">ps</span><span class="o">.</span><span class="n">ZVAL</span> <span class="o">*</span> <span class="n">num</span> <span class="k">for</span> <span class="n">ps</span><span class="p">,</span> <span class="n">num</span> <span class="ow">in</span>
                                    <span class="nb">zip</span><span class="p">(</span><span class="n">potcar</span><span class="p">,</span> <span class="n">nums</span><span class="p">))</span>
            <span class="n">charge</span> <span class="o">=</span> <span class="n">nelect</span> <span class="o">-</span> <span class="n">potcar_nelect</span>

            <span class="k">if</span> <span class="n">charge</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">:</span>
                    <span class="n">s</span><span class="o">.</span><span class="n">_charge</span> <span class="o">=</span> <span class="n">charge</span></div>

<div class="viewcode-block" id="Vasprun.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Vasprun.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;vasp_version&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">vasp_version</span><span class="p">,</span>
             <span class="s2">&quot;has_vasp_completed&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">converged</span><span class="p">,</span>
             <span class="s2">&quot;nsites&quot;</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="p">)}</span>
        <span class="n">comp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">composition</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;unit_cell_formula&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">comp</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;reduced_cell_formula&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Composition</span><span class="p">(</span><span class="n">comp</span><span class="o">.</span><span class="n">reduced_formula</span><span class="p">)</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;pretty_formula&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">comp</span><span class="o">.</span><span class="n">reduced_formula</span>
        <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
        <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">]</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;is_hubbard&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_hubbard</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;hubbards&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">hubbards</span>

        <span class="n">unique_symbols</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atomic_symbols</span><span class="p">)))</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;elements&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">unique_symbols</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;nelements&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">unique_symbols</span><span class="p">)</span>

        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;run_type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span>

        <span class="n">vin</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;incar&quot;</span><span class="p">:</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
               <span class="s2">&quot;crystal&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">initial_structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
               <span class="s2">&quot;kpoints&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()}</span>
        <span class="n">actual_kpts</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">&quot;abc&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]),</span>
                        <span class="s2">&quot;weight&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints_weights</span><span class="p">[</span><span class="n">i</span><span class="p">]}</span>
                       <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">))]</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">][</span><span class="s2">&quot;actual_points&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">actual_kpts</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;nkpoints&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">actual_kpts</span><span class="p">)</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;potcar&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;potcar_spec&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_spec</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;potcar_type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;parameters&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;lattice_rec&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">reciprocal_lattice</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;input&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vin</span>

        <span class="n">nsites</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="p">)</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">vout</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;ionic_steps&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">,</span>
                    <span class="s2">&quot;final_energy&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_energy</span><span class="p">,</span>
                    <span class="s2">&quot;final_energy_per_atom&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_energy</span> <span class="o">/</span> <span class="n">nsites</span><span class="p">,</span>
                    <span class="s2">&quot;crystal&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                    <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">}</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">ArithmeticError</span><span class="p">,</span> <span class="ne">TypeError</span><span class="p">):</span>
            <span class="n">vout</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;ionic_steps&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">,</span>
                    <span class="s2">&quot;final_energy&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_energy</span><span class="p">,</span>
                    <span class="s2">&quot;final_energy_per_atom&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="s2">&quot;crystal&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                    <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="p">:</span>
            <span class="n">eigen</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">v</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                     <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="n">vout</span><span class="p">[</span><span class="s2">&quot;eigenvalues&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">eigen</span>
            <span class="p">(</span><span class="n">gap</span><span class="p">,</span> <span class="n">cbm</span><span class="p">,</span> <span class="n">vbm</span><span class="p">,</span> <span class="n">is_direct</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalue_band_properties</span>
            <span class="n">vout</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">bandgap</span><span class="o">=</span><span class="n">gap</span><span class="p">,</span> <span class="n">cbm</span><span class="o">=</span><span class="n">cbm</span><span class="p">,</span> <span class="n">vbm</span><span class="o">=</span><span class="n">vbm</span><span class="p">,</span>
                             <span class="n">is_gap_direct</span><span class="o">=</span><span class="n">is_direct</span><span class="p">))</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span><span class="p">:</span>
                <span class="n">vout</span><span class="p">[</span><span class="s1">&#39;projected_eigenvalues&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
                    <span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="n">v</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                    <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

        <span class="n">vout</span><span class="p">[</span><span class="s1">&#39;epsilon_static&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_static</span>
        <span class="n">vout</span><span class="p">[</span><span class="s1">&#39;epsilon_static_wolfe&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_static_wolfe</span>
        <span class="n">vout</span><span class="p">[</span><span class="s1">&#39;epsilon_ionic&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">epsilon_ionic</span>
        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;output&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vout</span>
        <span class="k">return</span> <span class="n">jsanitize</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">_parse_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">elem</span><span class="p">:</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">tag</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;i&quot;</span><span class="p">,</span> <span class="s2">&quot;v&quot;</span><span class="p">):</span>
                <span class="n">p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_params</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;response functions&quot;</span><span class="p">:</span>
                    <span class="c1"># Delete duplicate fields from &quot;response functions&quot;,</span>
                    <span class="c1"># which overrides the values in the root params.</span>
                    <span class="n">p</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">params</span><span class="p">}</span>
                <span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">ptype</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;type&quot;</span><span class="p">)</span>
                <span class="n">val</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">text</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;i&quot;</span><span class="p">:</span>
                    <span class="n">params</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">_parse_parameters</span><span class="p">(</span><span class="n">ptype</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">params</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">_parse_v_parameters</span><span class="p">(</span><span class="n">ptype</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span>
                                                       <span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
        <span class="n">elem</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">Incar</span><span class="p">(</span><span class="n">params</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_parse_atominfo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;array&quot;</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">a</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;atoms&quot;</span><span class="p">:</span>
                <span class="n">atomic_symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">rc</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;c&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                                  <span class="k">for</span> <span class="n">rc</span> <span class="ow">in</span> <span class="n">a</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)]</span>
            <span class="k">elif</span> <span class="n">a</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;atomtypes&quot;</span><span class="p">:</span>
                <span class="n">potcar_symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">rc</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;c&quot;</span><span class="p">)[</span><span class="mi">4</span><span class="p">]</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                                  <span class="k">for</span> <span class="n">rc</span> <span class="ow">in</span> <span class="n">a</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)]</span>

        <span class="c1"># ensure atomic symbols are valid elements</span>
        <span class="k">def</span> <span class="nf">parse_atomic_symbol</span><span class="p">(</span><span class="n">symbol</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">symbol</span><span class="p">))</span>
            <span class="c1"># vasprun.xml uses X instead of Xe for xenon</span>
            <span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">symbol</span> <span class="o">==</span> <span class="s2">&quot;X&quot;</span><span class="p">:</span>
                    <span class="k">return</span> <span class="s2">&quot;Xe&quot;</span>
                <span class="k">elif</span> <span class="n">symbol</span> <span class="o">==</span> <span class="s2">&quot;r&quot;</span><span class="p">:</span>
                    <span class="k">return</span> <span class="s2">&quot;Zr&quot;</span>
                <span class="k">raise</span> <span class="n">e</span>

        <span class="n">elem</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">parse_atomic_symbol</span><span class="p">(</span><span class="n">sym</span><span class="p">)</span> <span class="k">for</span>
                <span class="n">sym</span> <span class="ow">in</span> <span class="n">atomic_symbols</span><span class="p">],</span> <span class="n">potcar_symbols</span>

    <span class="k">def</span> <span class="nf">_parse_kpoints</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">e</span> <span class="o">=</span> <span class="n">elem</span>
        <span class="k">if</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;generation&quot;</span><span class="p">):</span>
            <span class="n">e</span> <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;generation&quot;</span><span class="p">)</span>
        <span class="n">k</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="p">(</span><span class="s2">&quot;Kpoints from vasprun.xml&quot;</span><span class="p">)</span>
        <span class="n">k</span><span class="o">.</span><span class="n">style</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span>
            <span class="n">e</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;param&quot;</span><span class="p">]</span> <span class="k">if</span> <span class="s2">&quot;param&quot;</span> <span class="ow">in</span> <span class="n">e</span><span class="o">.</span><span class="n">attrib</span> <span class="k">else</span> <span class="s2">&quot;Reciprocal&quot;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">e</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;v&quot;</span><span class="p">):</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">v</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span>
            <span class="n">toks</span> <span class="o">=</span> <span class="n">v</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;divisions&quot;</span><span class="p">:</span>
                <span class="n">k</span><span class="o">.</span><span class="n">kpts</span> <span class="o">=</span> <span class="p">[[</span><span class="nb">int</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">]]</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;usershift&quot;</span><span class="p">:</span>
                <span class="n">k</span><span class="o">.</span><span class="n">kpts_shift</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">{</span><span class="s2">&quot;genvec1&quot;</span><span class="p">,</span> <span class="s2">&quot;genvec2&quot;</span><span class="p">,</span> <span class="s2">&quot;genvec3&quot;</span><span class="p">,</span> <span class="s2">&quot;shift&quot;</span><span class="p">}:</span>
                <span class="nb">setattr</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">va</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;varray&quot;</span><span class="p">):</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">va</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;kpointlist&quot;</span><span class="p">:</span>
                <span class="n">actual_kpoints</span> <span class="o">=</span> <span class="n">_parse_varray</span><span class="p">(</span><span class="n">va</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;weights&quot;</span><span class="p">:</span>
                <span class="n">weights</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">_parse_varray</span><span class="p">(</span><span class="n">va</span><span class="p">)]</span>
        <span class="n">elem</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">k</span><span class="o">.</span><span class="n">style</span> <span class="o">==</span> <span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Reciprocal</span><span class="p">:</span>
            <span class="n">k</span> <span class="o">=</span> <span class="n">Kpoints</span><span class="p">(</span><span class="n">comment</span><span class="o">=</span><span class="s2">&quot;Kpoints from vasprun.xml&quot;</span><span class="p">,</span>
                        <span class="n">style</span><span class="o">=</span><span class="n">Kpoints</span><span class="o">.</span><span class="n">supported_modes</span><span class="o">.</span><span class="n">Reciprocal</span><span class="p">,</span>
                        <span class="n">num_kpts</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">k</span><span class="o">.</span><span class="n">kpts</span><span class="p">),</span>
                        <span class="n">kpts</span><span class="o">=</span><span class="n">actual_kpoints</span><span class="p">,</span> <span class="n">kpts_weights</span><span class="o">=</span><span class="n">weights</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">k</span><span class="p">,</span> <span class="n">actual_kpoints</span><span class="p">,</span> <span class="n">weights</span>

    <span class="k">def</span> <span class="nf">_parse_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">latt</span> <span class="o">=</span> <span class="n">_parse_varray</span><span class="p">(</span><span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;crystal&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;varray&quot;</span><span class="p">))</span>
        <span class="n">pos</span> <span class="o">=</span> <span class="n">_parse_varray</span><span class="p">(</span><span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;varray&quot;</span><span class="p">))</span>
        <span class="n">struct</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="n">latt</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">atomic_symbols</span><span class="p">,</span> <span class="n">pos</span><span class="p">)</span>
        <span class="n">sdyn</span> <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;varray/[@name=&#39;selective&#39;]&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">sdyn</span><span class="p">:</span>
            <span class="n">struct</span><span class="o">.</span><span class="n">add_site_property</span><span class="p">(</span><span class="s1">&#39;selective_dynamics&#39;</span><span class="p">,</span>
                                     <span class="n">_parse_varray</span><span class="p">(</span><span class="n">sdyn</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">struct</span>

    <span class="k">def</span> <span class="nf">_parse_diel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">imag</span> <span class="o">=</span> <span class="p">[[</span><span class="n">_vasprun_float</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">r</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
                <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;imag&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;array&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;r&quot;</span><span class="p">)]</span>
        <span class="n">real</span> <span class="o">=</span> <span class="p">[[</span><span class="n">_vasprun_float</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">r</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
                <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;real&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;array&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;r&quot;</span><span class="p">)]</span>
        <span class="n">elem</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">imag</span><span class="p">],</span> \
               <span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">real</span><span class="p">],</span> <span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">imag</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">_parse_optical_transition</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">va</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;varray&quot;</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">va</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;opticaltransitions&quot;</span><span class="p">:</span>
                <span class="c1"># opticaltransitions array contains oscillator strength and probability of transition</span>
                <span class="n">oscillator_strength</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">_parse_varray</span><span class="p">(</span><span class="n">va</span><span class="p">))[</span><span class="mi">0</span><span class="p">:,</span> <span class="p">]</span>
                <span class="n">probability_transition</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">_parse_varray</span><span class="p">(</span><span class="n">va</span><span class="p">))[</span><span class="mi">0</span><span class="p">:,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">oscillator_strength</span><span class="p">,</span> <span class="n">probability_transition</span>

    <span class="k">def</span> <span class="nf">_parse_chemical_shielding_calculation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">calculation</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">istep</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_structure</span><span class="p">(</span><span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;structure&quot;</span><span class="p">))</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>  <span class="c1"># not all calculations have a structure</span>
            <span class="n">s</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">pass</span>
        <span class="k">for</span> <span class="n">va</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;varray&quot;</span><span class="p">):</span>
            <span class="n">istep</span><span class="p">[</span><span class="n">va</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]]</span> <span class="o">=</span> <span class="n">_parse_varray</span><span class="p">(</span><span class="n">va</span><span class="p">)</span>
        <span class="n">istep</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">s</span>
        <span class="n">istep</span><span class="p">[</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">calculation</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">istep</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">scstep</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;scstep&quot;</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="n">i</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]:</span> <span class="n">_vasprun_float</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
                     <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">scstep</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;energy&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;i&quot;</span><span class="p">)}</span>
                <span class="n">cur_ene</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s1">&#39;e_fr_energy&#39;</span><span class="p">]</span>
                <span class="n">min_steps</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">calculation</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">1</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;NELMIN&quot;</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">calculation</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">])</span> <span class="o">&lt;=</span> <span class="n">min_steps</span><span class="p">:</span>
                    <span class="n">calculation</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">last_ene</span> <span class="o">=</span> <span class="n">calculation</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;e_fr_energy&quot;</span><span class="p">]</span>
                    <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">cur_ene</span> <span class="o">-</span> <span class="n">last_ene</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">:</span>
                        <span class="n">calculation</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">calculation</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">d</span><span class="p">]})</span>
            <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>  <span class="c1"># not all calculations have an energy</span>
                <span class="k">pass</span>
        <span class="n">calculation</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">calculation</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">calculation</span>

    <span class="k">def</span> <span class="nf">_parse_calculation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">istep</span> <span class="o">=</span> <span class="p">{</span><span class="n">i</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]:</span> <span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
                     <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;energy&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;i&quot;</span><span class="p">)}</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>  <span class="c1"># not all calculations have an energy</span>
            <span class="n">istep</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">pass</span>
        <span class="n">esteps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">scstep</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;scstep&quot;</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="n">i</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]:</span> <span class="n">_vasprun_float</span><span class="p">(</span><span class="n">i</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
                     <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">scstep</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;energy&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;i&quot;</span><span class="p">)}</span>
                <span class="n">esteps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>  <span class="c1"># not all calculations have an energy</span>
                <span class="k">pass</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_structure</span><span class="p">(</span><span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;structure&quot;</span><span class="p">))</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>  <span class="c1"># not all calculations have a structure</span>
            <span class="n">s</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">pass</span>
        <span class="k">for</span> <span class="n">va</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;varray&quot;</span><span class="p">):</span>
            <span class="n">istep</span><span class="p">[</span><span class="n">va</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]]</span> <span class="o">=</span> <span class="n">_parse_varray</span><span class="p">(</span><span class="n">va</span><span class="p">)</span>
        <span class="n">istep</span><span class="p">[</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">esteps</span>
        <span class="n">istep</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">s</span>
        <span class="n">elem</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">istep</span>

    <span class="k">def</span> <span class="nf">_parse_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">efermi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;i&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
        <span class="n">energies</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">tdensities</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">idensities</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;total&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;array&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">):</span>
            <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">_parse_varray</span><span class="p">(</span><span class="n">s</span><span class="p">))</span>
            <span class="n">energies</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span> <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;spin 1&quot;</span> <span class="k">else</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span>
            <span class="n">tdensities</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
            <span class="n">idensities</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]</span>

        <span class="n">pdoss</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">partial</span> <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;partial&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">partial</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">orbs</span> <span class="o">=</span> <span class="p">[</span><span class="n">ss</span><span class="o">.</span><span class="n">text</span> <span class="k">for</span> <span class="n">ss</span> <span class="ow">in</span> <span class="n">partial</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;array&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;field&quot;</span><span class="p">)]</span>
            <span class="n">orbs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">lm</span> <span class="o">=</span> <span class="nb">any</span><span class="p">([</span><span class="s2">&quot;x&quot;</span> <span class="ow">in</span> <span class="n">s</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">orbs</span><span class="p">])</span>
            <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">partial</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;array&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">):</span>
                <span class="n">pdos</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">dict</span><span class="p">)</span>

                <span class="k">for</span> <span class="n">ss</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">):</span>
                    <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span> <span class="k">if</span> <span class="n">ss</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;spin 1&quot;</span> <span class="k">else</span> \
                        <span class="n">Spin</span><span class="o">.</span><span class="n">down</span>
                    <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">_parse_varray</span><span class="p">(</span><span class="n">ss</span><span class="p">))</span>
                    <span class="n">nrow</span><span class="p">,</span> <span class="n">ncol</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">shape</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">ncol</span><span class="p">):</span>
                        <span class="k">if</span> <span class="n">lm</span><span class="p">:</span>
                            <span class="n">orb</span> <span class="o">=</span> <span class="n">Orbital</span><span class="p">(</span><span class="n">j</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="n">orb</span> <span class="o">=</span> <span class="n">OrbitalType</span><span class="p">(</span><span class="n">j</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
                        <span class="n">pdos</span><span class="p">[</span><span class="n">orb</span><span class="p">][</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:,</span> <span class="n">j</span><span class="p">]</span>
                <span class="n">pdoss</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pdos</span><span class="p">)</span>
        <span class="n">elem</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">Dos</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">tdensities</span><span class="p">),</span> <span class="n">Dos</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">idensities</span><span class="p">),</span> <span class="n">pdoss</span>

    <span class="k">def</span> <span class="nf">_parse_eigen</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">eigenvalues</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;array&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">):</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span> <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;spin 1&quot;</span> <span class="k">else</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span>
            <span class="k">for</span> <span class="n">ss</span> <span class="ow">in</span> <span class="n">s</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">):</span>
                <span class="n">eigenvalues</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_parse_varray</span><span class="p">(</span><span class="n">ss</span><span class="p">))</span>
        <span class="n">eigenvalues</span> <span class="o">=</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">eigenvalues</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">elem</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">eigenvalues</span>

    <span class="k">def</span> <span class="nf">_parse_projected_eigen</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">root</span> <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;array&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)</span>
        <span class="n">proj_eigen</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">root</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">):</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;spin(\d+)&quot;</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;comment&quot;</span><span class="p">])</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>

            <span class="c1"># Force spin to be +1 or -1</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span> <span class="k">if</span> <span class="n">spin</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span>
            <span class="k">for</span> <span class="n">kpt</span><span class="p">,</span> <span class="n">ss</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)):</span>
                <span class="n">dk</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">band</span><span class="p">,</span> <span class="n">sss</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ss</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;set&quot;</span><span class="p">)):</span>
                    <span class="n">db</span> <span class="o">=</span> <span class="n">_parse_varray</span><span class="p">(</span><span class="n">sss</span><span class="p">)</span>
                    <span class="n">dk</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">db</span><span class="p">)</span>
                <span class="n">proj_eigen</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dk</span><span class="p">)</span>
        <span class="n">proj_eigen</span> <span class="o">=</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">proj_eigen</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">elem</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">proj_eigen</span>

    <span class="k">def</span> <span class="nf">_parse_dynmat</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span>
        <span class="n">hessian</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">eigenvalues</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">eigenvectors</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;v&quot;</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">v</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;eigenvalues&quot;</span><span class="p">:</span>
                <span class="n">eigenvalues</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
        <span class="k">for</span> <span class="n">va</span> <span class="ow">in</span> <span class="n">elem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;varray&quot;</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">va</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;hessian&quot;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">va</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;v&quot;</span><span class="p">):</span>
                    <span class="n">hessian</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>
            <span class="k">elif</span> <span class="n">va</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;eigenvectors&quot;</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">va</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">&quot;v&quot;</span><span class="p">):</span>
                    <span class="n">eigenvectors</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">v</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>
        <span class="k">return</span> <span class="n">hessian</span><span class="p">,</span> <span class="n">eigenvalues</span><span class="p">,</span> <span class="n">eigenvectors</span></div>


<div class="viewcode-block" id="BSVasprun"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.BSVasprun">[docs]</a><span class="k">class</span> <span class="nc">BSVasprun</span><span class="p">(</span><span class="n">Vasprun</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A highly optimized version of Vasprun that parses only eigenvalues for</span>
<span class="sd">    bandstructures. All other properties like structures, parameters,</span>
<span class="sd">    etc. are ignored.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">parse_projected_eigen</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">parse_potcar_file</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">occu_tol</span><span class="o">=</span><span class="mf">1e-8</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename to parse</span>
<span class="sd">            parse_projected_eigen (bool): Whether to parse the projected</span>
<span class="sd">                eigenvalues. Defaults to False. Set to True to obtain projected</span>
<span class="sd">                eigenvalues. **Note that this can take an extreme amount of time</span>
<span class="sd">                and memory.** So use this wisely.</span>
<span class="sd">            parse_potcar_file (bool/str): Whether to parse the potcar file to read</span>
<span class="sd">                the potcar hashes for the potcar_spec attribute. Defaults to True,</span>
<span class="sd">                where no hashes will be determined and the potcar_spec dictionaries</span>
<span class="sd">                will read {&quot;symbol&quot;: ElSymbol, &quot;hash&quot;: None}. By Default, looks in</span>
<span class="sd">                the same directory as the vasprun.xml, with same extensions as</span>
<span class="sd">                 Vasprun.xml. If a string is provided, looks at that filepath.</span>
<span class="sd">            occu_tol (float): Sets the minimum tol for the determination of the</span>
<span class="sd">                vbm and cbm. Usually the default of 1e-8 works well enough,</span>
<span class="sd">                but there may be pathological cases.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">occu_tol</span> <span class="o">=</span> <span class="n">occu_tol</span>

        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">parsed_header</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">for</span> <span class="n">event</span><span class="p">,</span> <span class="n">elem</span> <span class="ow">in</span> <span class="n">ET</span><span class="o">.</span><span class="n">iterparse</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
                <span class="n">tag</span> <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="n">tag</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">parsed_header</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;generator&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">generator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_params</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;incar&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">incar</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_params</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;kpoints&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints_weights</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_kpoints</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;parameters&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_params</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;atominfo&quot;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">atomic_symbols</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_atominfo</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">potcar_spec</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">&quot;titel&quot;</span><span class="p">:</span> <span class="n">p</span><span class="p">,</span> <span class="s2">&quot;hash&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
                        <span class="n">parsed_header</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;i&quot;</span> <span class="ow">and</span> <span class="n">elem</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;efermi&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">elem</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;eigenvalues&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_eigen</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">parse_projected_eigen</span> <span class="ow">and</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;projected&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_projected_eigen</span><span class="p">(</span>
                        <span class="n">elem</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">tag</span> <span class="o">==</span> <span class="s2">&quot;structure&quot;</span> <span class="ow">and</span> <span class="n">elem</span><span class="o">.</span><span class="n">attrib</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">)</span> <span class="o">==</span> \
                        <span class="s2">&quot;finalpos&quot;</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_structure</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">vasp_version</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">parse_potcar_file</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">update_potcar_spec</span><span class="p">(</span><span class="n">parse_potcar_file</span><span class="p">)</span>

<div class="viewcode-block" id="BSVasprun.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.BSVasprun.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;vasp_version&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">vasp_version</span><span class="p">,</span>
             <span class="s2">&quot;has_vasp_completed&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
             <span class="s2">&quot;nsites&quot;</span><span class="p">:</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="p">)}</span>
        <span class="n">comp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">composition</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;unit_cell_formula&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">comp</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;reduced_cell_formula&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Composition</span><span class="p">(</span><span class="n">comp</span><span class="o">.</span><span class="n">reduced_formula</span><span class="p">)</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;pretty_formula&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">comp</span><span class="o">.</span><span class="n">reduced_formula</span>
        <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
        <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;_&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">symbols</span><span class="p">]</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;is_hubbard&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_hubbard</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;hubbards&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">hubbards</span>

        <span class="n">unique_symbols</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atomic_symbols</span><span class="p">)))</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;elements&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">unique_symbols</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;nelements&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">unique_symbols</span><span class="p">)</span>

        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;run_type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_type</span>

        <span class="n">vin</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;incar&quot;</span><span class="p">:</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">incar</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
               <span class="s2">&quot;crystal&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
               <span class="s2">&quot;kpoints&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()}</span>
        <span class="n">actual_kpts</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">&quot;abc&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">[</span><span class="n">i</span><span class="p">]),</span>
                        <span class="s2">&quot;weight&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints_weights</span><span class="p">[</span><span class="n">i</span><span class="p">]}</span>
                       <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">actual_kpoints</span><span class="p">))]</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;kpoints&quot;</span><span class="p">][</span><span class="s2">&quot;actual_points&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">actual_kpts</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;potcar&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;potcar_spec&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_spec</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;potcar_type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">potcar_symbols</span><span class="p">]</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;parameters&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">vin</span><span class="p">[</span><span class="s2">&quot;lattice_rec&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">reciprocal_lattice</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;input&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vin</span>

        <span class="n">vout</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;crystal&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">final_structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
                <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="p">:</span>
            <span class="n">eigen</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">dict</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">values</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">values</span><span class="p">):</span>
                    <span class="n">eigen</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">)]</span> <span class="o">=</span> <span class="n">v</span>
            <span class="n">vout</span><span class="p">[</span><span class="s2">&quot;eigenvalues&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">eigen</span>
            <span class="p">(</span><span class="n">gap</span><span class="p">,</span> <span class="n">cbm</span><span class="p">,</span> <span class="n">vbm</span><span class="p">,</span> <span class="n">is_direct</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalue_band_properties</span>
            <span class="n">vout</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">bandgap</span><span class="o">=</span><span class="n">gap</span><span class="p">,</span> <span class="n">cbm</span><span class="o">=</span><span class="n">cbm</span><span class="p">,</span> <span class="n">vbm</span><span class="o">=</span><span class="n">vbm</span><span class="p">,</span>
                             <span class="n">is_gap_direct</span><span class="o">=</span><span class="n">is_direct</span><span class="p">))</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span><span class="p">:</span>
                <span class="n">peigen</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">eigen</span><span class="p">)):</span>
                    <span class="n">peigen</span><span class="o">.</span><span class="n">append</span><span class="p">({})</span>
                <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">projected_eigenvalues</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">for</span> <span class="n">kpoint_index</span><span class="p">,</span> <span class="n">vv</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">v</span><span class="p">):</span>
                        <span class="k">if</span> <span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">peigen</span><span class="p">[</span><span class="n">kpoint_index</span><span class="p">]:</span>
                            <span class="n">peigen</span><span class="p">[</span><span class="n">kpoint_index</span><span class="p">][</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">)]</span> <span class="o">=</span> <span class="n">vv</span>
                <span class="n">vout</span><span class="p">[</span><span class="s1">&#39;projected_eigenvalues&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">peigen</span>

        <span class="n">d</span><span class="p">[</span><span class="s1">&#39;output&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">vout</span>
        <span class="k">return</span> <span class="n">jsanitize</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Outcar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar">[docs]</a><span class="k">class</span> <span class="nc">Outcar</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Parser for data in OUTCAR that is not available in Vasprun.xml</span>

<span class="sd">    Note, this class works a bit differently than most of the other</span>
<span class="sd">    VaspObjects, since the OUTCAR can be very different depending on which</span>
<span class="sd">    &quot;type of run&quot; performed.</span>

<span class="sd">    Creating the OUTCAR class with a filename reads &quot;regular parameters&quot; that</span>
<span class="sd">    are always present.</span>

<span class="sd">    .. attribute:: magnetization</span>

<span class="sd">        Magnetization on each ion as a tuple of dict, e.g.,</span>
<span class="sd">        ({&quot;d&quot;: 0.0, &quot;p&quot;: 0.003, &quot;s&quot;: 0.002, &quot;tot&quot;: 0.005}, ... )</span>
<span class="sd">        Note that this data is not always present.  LORBIT must be set to some</span>
<span class="sd">        other value than the default.</span>

<span class="sd">    .. attribute:: chemical_shielding</span>

<span class="sd">        chemical shielding on each ion as a dictionary with core and valence contributions</span>

<span class="sd">    .. attribute:: unsym_cs_tensor</span>

<span class="sd">        Unsymmetrized chemical shielding tensor matrixes on each ion as a list.</span>
<span class="sd">        e.g.,</span>
<span class="sd">        [[[sigma11, sigma12, sigma13],</span>
<span class="sd">          [sigma21, sigma22, sigma23],</span>
<span class="sd">          [sigma31, sigma32, sigma33]],</span>
<span class="sd">          ...</span>
<span class="sd">         [[sigma11, sigma12, sigma13],</span>
<span class="sd">          [sigma21, sigma22, sigma23],</span>
<span class="sd">          [sigma31, sigma32, sigma33]]]</span>

<span class="sd">    .. attribute:: cs_g0_contribution</span>

<span class="sd">        G=0 contribution to chemical shielding. 2D rank 3 matrix</span>

<span class="sd">    .. attribute:: cs_core_contribution</span>

<span class="sd">        Core contribution to chemical shielding. dict. e.g.,</span>
<span class="sd">        {&#39;Mg&#39;: -412.8, &#39;C&#39;: -200.5, &#39;O&#39;: -271.1}</span>

<span class="sd">    .. attribute:: efg</span>

<span class="sd">        Electric Field Gradient (EFG) tensor on each ion as a tuple of dict, e.g.,</span>
<span class="sd">        ({&quot;cq&quot;: 0.1, &quot;eta&quot;, 0.2, &quot;nuclear_quadrupole_moment&quot;: 0.3},</span>
<span class="sd">         {&quot;cq&quot;: 0.7, &quot;eta&quot;, 0.8, &quot;nuclear_quadrupole_moment&quot;: 0.9},</span>
<span class="sd">         ...)</span>

<span class="sd">    .. attribute:: charge</span>

<span class="sd">        Charge on each ion as a tuple of dict, e.g.,</span>
<span class="sd">        ({&quot;p&quot;: 0.154, &quot;s&quot;: 0.078, &quot;d&quot;: 0.0, &quot;tot&quot;: 0.232}, ...)</span>
<span class="sd">        Note that this data is not always present.  LORBIT must be set to some</span>
<span class="sd">        other value than the default.</span>

<span class="sd">    .. attribute:: is_stopped</span>

<span class="sd">        True if OUTCAR is from a stopped run (using STOPCAR, see Vasp Manual).</span>

<span class="sd">    .. attribute:: run_stats</span>

<span class="sd">        Various useful run stats as a dict including &quot;System time (sec)&quot;,</span>
<span class="sd">        &quot;Total CPU time used (sec)&quot;, &quot;Elapsed time (sec)&quot;,</span>
<span class="sd">        &quot;Maximum memory used (kb)&quot;, &quot;Average memory used (kb)&quot;,</span>
<span class="sd">        &quot;User time (sec)&quot;.</span>

<span class="sd">    .. attribute:: elastic_tensor</span>
<span class="sd">        Total elastic moduli (Kbar) is given in a 6x6 array matrix.</span>

<span class="sd">    .. attribute:: drift</span>
<span class="sd">        Total drift for each step in eV/Atom</span>

<span class="sd">    .. attribute:: ngf</span>
<span class="sd">        Dimensions for the Augementation grid</span>

<span class="sd">    .. attribute: sampling_radii</span>
<span class="sd">        Size of the sampling radii in VASP for the test charges for</span>
<span class="sd">        the electrostatic potential at each atom. Total array size is the number</span>
<span class="sd">        of elements present in the calculation</span>

<span class="sd">    .. attribute: electrostatic_potential</span>
<span class="sd">        Average electrostatic potential at each atomic position in order</span>
<span class="sd">        of the atoms in POSCAR.</span>

<span class="sd">    ..attribute: final_energy_contribs</span>
<span class="sd">        Individual contributions to the total final energy as a dictionary.</span>
<span class="sd">        Include contirbutions from keys, e.g.:</span>
<span class="sd">        {&#39;DENC&#39;: -505778.5184347, &#39;EATOM&#39;: 15561.06492564, &#39;EBANDS&#39;: -804.53201231,</span>
<span class="sd">        &#39;EENTRO&#39;: -0.08932659, &#39;EXHF&#39;: 0.0, &#39;Ediel_sol&#39;: 0.0,</span>
<span class="sd">        &#39;PAW double counting&#39;: 664.6726974100002, &#39;PSCENC&#39;: 742.48691646,</span>
<span class="sd">        &#39;TEWEN&#39;: 489742.86847338, &#39;XCENC&#39;: -169.64189814}</span>

<span class="sd">    One can then call a specific reader depending on the type of run being</span>
<span class="sd">    performed. These are currently: read_igpar(), read_lepsilon() and</span>
<span class="sd">    read_lcalcpol(), read_core_state_eign(), read_avg_core_pot().</span>

<span class="sd">    See the documentation of those methods for more documentation.</span>

<span class="sd">    Authors: Rickard Armiento, Shyue Ping Ong</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filename (str): OUTCAR filename to parse.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_stopped</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="c1"># data from end of OUTCAR</span>
        <span class="n">charge</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">mag_x</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">mag_y</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">mag_z</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">header</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">run_stats</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">total_mag</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">nelect</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">efermi</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">total_energy</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="n">time_patt</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\((sec|kb)\)&quot;</span><span class="p">)</span>
        <span class="n">efermi_patt</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;E-fermi\s*:\s*(\S+)&quot;</span><span class="p">)</span>
        <span class="n">nelect_patt</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;number of electron\s+(\S+)\s+magnetization&quot;</span><span class="p">)</span>
        <span class="n">mag_patt</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;number of electron\s+\S+\s+magnetization\s+(&quot;</span>
                              <span class="sa">r</span><span class="s2">&quot;\S+)&quot;</span><span class="p">)</span>
        <span class="n">toten_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;free  energy   TOTEN\s+=\s+([\d\-\.]+)&quot;</span><span class="p">)</span>

        <span class="n">all_lines</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">reverse_readfile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">):</span>
            <span class="n">clean</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">all_lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">clean</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">clean</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">&quot;soft stop encountered!  aborting job&quot;</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">is_stopped</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">time_patt</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">line</span><span class="p">):</span>
                    <span class="n">tok</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>
                    <span class="n">run_stats</span><span class="p">[</span><span class="n">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">tok</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
                    <span class="k">continue</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">efermi_patt</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">clean</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="c1"># try-catch because VASP sometimes prints</span>
                        <span class="c1"># &#39;E-fermi: ********     XC(G=0):  -6.1327</span>
                        <span class="c1"># alpha+bet : -1.8238&#39;</span>
                        <span class="n">efermi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
                        <span class="k">continue</span>
                    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                        <span class="n">efermi</span> <span class="o">=</span> <span class="kc">None</span>
                        <span class="k">continue</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">nelect_patt</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">clean</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                    <span class="n">nelect</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">mag_patt</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">clean</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                    <span class="n">total_mag</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">total_energy</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">toten_pattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">clean</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                        <span class="n">total_energy</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
            <span class="k">if</span> <span class="nb">all</span><span class="p">([</span><span class="n">nelect</span><span class="p">,</span> <span class="n">total_mag</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">,</span> <span class="n">efermi</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="n">run_stats</span><span class="p">]):</span>
                <span class="k">break</span>

        <span class="c1"># For single atom systems, VASP doesn&#39;t print a total line, so</span>
        <span class="c1"># reverse parsing is very difficult</span>
        <span class="n">read_charge</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">read_mag_x</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">read_mag_y</span> <span class="o">=</span> <span class="kc">False</span>  <span class="c1"># for SOC calculations only</span>
        <span class="n">read_mag_z</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">all_lines</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">clean</span> <span class="ow">in</span> <span class="n">all_lines</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">read_charge</span> <span class="ow">or</span> <span class="n">read_mag_x</span> <span class="ow">or</span> <span class="n">read_mag_y</span> <span class="ow">or</span> <span class="n">read_mag_z</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">clean</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;# of ion&quot;</span><span class="p">):</span>
                    <span class="n">header</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\s{2,}&quot;</span><span class="p">,</span> <span class="n">clean</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
                    <span class="n">header</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\s*(\d+)\s+(([\d\.\-]+)\s+)+&quot;</span><span class="p">,</span> <span class="n">clean</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                        <span class="n">toks</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
                                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;[\d\.\-]+&quot;</span><span class="p">,</span> <span class="n">clean</span><span class="p">)]</span>
                        <span class="n">toks</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
                        <span class="k">if</span> <span class="n">read_charge</span><span class="p">:</span>
                            <span class="n">charge</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">header</span><span class="p">,</span> <span class="n">toks</span><span class="p">)))</span>
                        <span class="k">elif</span> <span class="n">read_mag_x</span><span class="p">:</span>
                            <span class="n">mag_x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">header</span><span class="p">,</span> <span class="n">toks</span><span class="p">)))</span>
                        <span class="k">elif</span> <span class="n">read_mag_y</span><span class="p">:</span>
                            <span class="n">mag_y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">header</span><span class="p">,</span> <span class="n">toks</span><span class="p">)))</span>
                        <span class="k">elif</span> <span class="n">read_mag_z</span><span class="p">:</span>
                            <span class="n">mag_z</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">header</span><span class="p">,</span> <span class="n">toks</span><span class="p">)))</span>
                    <span class="k">elif</span> <span class="n">clean</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;tot&#39;</span><span class="p">):</span>
                        <span class="n">read_charge</span> <span class="o">=</span> <span class="kc">False</span>
                        <span class="n">read_mag_x</span> <span class="o">=</span> <span class="kc">False</span>
                        <span class="n">read_mag_y</span> <span class="o">=</span> <span class="kc">False</span>
                        <span class="n">read_mag_z</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">clean</span> <span class="o">==</span> <span class="s2">&quot;total charge&quot;</span><span class="p">:</span>
                <span class="n">charge</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">read_charge</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="n">read_mag_x</span><span class="p">,</span> <span class="n">read_mag_y</span><span class="p">,</span> <span class="n">read_mag_z</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">clean</span> <span class="o">==</span> <span class="s2">&quot;magnetization (x)&quot;</span><span class="p">:</span>
                <span class="n">mag_x</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">read_mag_x</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="n">read_charge</span><span class="p">,</span> <span class="n">read_mag_y</span><span class="p">,</span> <span class="n">read_mag_z</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">clean</span> <span class="o">==</span> <span class="s2">&quot;magnetization (y)&quot;</span><span class="p">:</span>
                <span class="n">mag_y</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">read_mag_y</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="n">read_charge</span><span class="p">,</span> <span class="n">read_mag_x</span><span class="p">,</span> <span class="n">read_mag_z</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">clean</span> <span class="o">==</span> <span class="s2">&quot;magnetization (z)&quot;</span><span class="p">:</span>
                <span class="n">mag_z</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">read_mag_z</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="n">read_charge</span><span class="p">,</span> <span class="n">read_mag_x</span><span class="p">,</span> <span class="n">read_mag_y</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s2">&quot;electrostatic&quot;</span><span class="p">,</span> <span class="n">clean</span><span class="p">):</span>
                <span class="n">read_charge</span><span class="p">,</span> <span class="n">read_mag_x</span><span class="p">,</span> <span class="n">read_mag_y</span><span class="p">,</span> <span class="n">read_mag_z</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">False</span>

        <span class="c1"># merge x, y and z components of magmoms if present (SOC calculation)</span>
        <span class="k">if</span> <span class="n">mag_y</span> <span class="ow">and</span> <span class="n">mag_z</span><span class="p">:</span>
            <span class="c1"># TODO: detect spin axis</span>
            <span class="n">mag</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">mag_x</span><span class="p">)):</span>
                <span class="n">mag</span><span class="o">.</span><span class="n">append</span><span class="p">({</span>
                    <span class="n">key</span><span class="p">:</span> <span class="n">Magmom</span><span class="p">([</span><span class="n">mag_x</span><span class="p">[</span><span class="n">idx</span><span class="p">][</span><span class="n">key</span><span class="p">],</span> <span class="n">mag_y</span><span class="p">[</span><span class="n">idx</span><span class="p">][</span><span class="n">key</span><span class="p">],</span> <span class="n">mag_z</span><span class="p">[</span><span class="n">idx</span><span class="p">][</span><span class="n">key</span><span class="p">]])</span>
                    <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">mag_x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
                <span class="p">})</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mag</span> <span class="o">=</span> <span class="n">mag_x</span>

        <span class="c1"># data from beginning of OUTCAR</span>
        <span class="n">run_stats</span><span class="p">[</span><span class="s1">&#39;cores&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="s2">&quot;running&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">run_stats</span><span class="p">[</span><span class="s1">&#39;cores&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">2</span><span class="p">]</span>
                    <span class="k">break</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">run_stats</span> <span class="o">=</span> <span class="n">run_stats</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">magnetization</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">mag</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">charge</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">charge</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="n">efermi</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nelect</span> <span class="o">=</span> <span class="n">nelect</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">total_mag</span> <span class="o">=</span> <span class="n">total_mag</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">final_energy</span> <span class="o">=</span> <span class="n">total_energy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="c1"># Read &quot;total number of plane waves&quot;, NPLWV:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">(</span>
            <span class="p">{</span><span class="s2">&quot;nplwv&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;total plane-waves  NPLWV =\s+(\*</span><span class="si">{6}</span><span class="s2">|\d+)&quot;</span><span class="p">},</span>
            <span class="n">terminate_on_match</span><span class="o">=</span><span class="kc">True</span>
        <span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;nplwv&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[[</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;nplwv&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">])]]</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;nplwv&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[[</span><span class="kc">None</span><span class="p">]]</span>

        <span class="n">nplwvs_at_kpoints</span> <span class="o">=</span> <span class="p">[</span>
            <span class="n">n</span> <span class="k">for</span> <span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span>
                <span class="sa">r</span><span class="s2">&quot;\n</span><span class="si">{3}</span><span class="s2">-</span><span class="si">{104}</span><span class="s2">\n</span><span class="si">{3}</span><span class="s2">&quot;</span><span class="p">,</span>
                <span class="sa">r</span><span class="s2">&quot;.+plane waves:\s+(\*{6,}|\d+)&quot;</span><span class="p">,</span>
                <span class="sa">r</span><span class="s2">&quot;maximum and minimum number of plane-waves&quot;</span>
            <span class="p">)</span>
        <span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;nplwvs_at_kpoints&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">nplwvs_at_kpoints</span><span class="p">]</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">nplwv</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">nplwvs_at_kpoints</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;nplwvs_at_kpoints&quot;</span><span class="p">][</span><span class="n">n</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">nplwv</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                <span class="k">pass</span>

        <span class="c1"># Read the drift:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span>
            <span class="s2">&quot;drift&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;total drift:\s+([\.\-\d]+)\s+([\.\-\d]+)\s+([\.\-\d]+)&quot;</span><span class="p">},</span>
            <span class="n">terminate_on_match</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">drift</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;drift&#39;</span><span class="p">,</span> <span class="p">[])</span>

        <span class="c1"># Check if calculation is spin polarized</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="s1">&#39;spin&#39;</span><span class="p">:</span> <span class="s1">&#39;ISPIN  =      2&#39;</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;spin&#39;</span><span class="p">,</span> <span class="p">[]):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="o">=</span> <span class="kc">True</span>

        <span class="c1"># Check if calculation is noncollinear</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">noncollinear</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="s1">&#39;noncollinear&#39;</span><span class="p">:</span> <span class="s1">&#39;LNONCOLLINEAR =      T&#39;</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;noncollinear&#39;</span><span class="p">,</span> <span class="p">[]):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">noncollinear</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="c1"># Check if the calculation type is DFPT</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dfpt</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="s1">&#39;ibrion&#39;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;IBRION =\s+([\-\d]+)&quot;</span><span class="p">},</span>
                          <span class="n">terminate_on_match</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                          <span class="n">postprocess</span><span class="o">=</span><span class="nb">int</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;ibrion&quot;</span><span class="p">,</span> <span class="p">[[</span><span class="mi">0</span><span class="p">]])[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">6</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dfpt</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_internal_strain_tensor</span><span class="p">()</span>

        <span class="c1"># Check to see if LEPSILON is true and read piezo data if so</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lepsilon</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="s1">&#39;epsilon&#39;</span><span class="p">:</span> <span class="s1">&#39;LEPSILON=     T&#39;</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;epsilon&#39;</span><span class="p">,</span> <span class="p">[]):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">lepsilon</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_lepsilon</span><span class="p">()</span>
            <span class="c1"># only read ionic contribution if DFPT is turned on</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dfpt</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">read_lepsilon_ionic</span><span class="p">()</span>

        <span class="c1"># Check to see if LCALCPOL is true and read polarization data if so</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lcalcpol</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="s1">&#39;calcpol&#39;</span><span class="p">:</span> <span class="s1">&#39;LCALCPOL   =     T&#39;</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;calcpol&#39;</span><span class="p">,</span> <span class="p">[]):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">lcalcpol</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_lcalcpol</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_pseudo_zval</span><span class="p">()</span>

        <span class="c1"># Read electrostatic potential</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span>
            <span class="s1">&#39;electrostatic&#39;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;average \(electrostatic\) potential at core&quot;</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;electrostatic&#39;</span><span class="p">,</span> <span class="p">[]):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_electrostatic_potential</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">nmr_cs</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="s2">&quot;nmr_cs&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;LCHIMAG   =     (T)&quot;</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;nmr_cs&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nmr_cs</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_chemical_shielding</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_cs_g0_contribution</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_cs_core_contribution</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_cs_raw_symmetrized_tensors</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">nmr_efg</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="s2">&quot;nmr_efg&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;NMR quadrupolar parameters&quot;</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;nmr_efg&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nmr_efg</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_nmr_efg</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_nmr_efg_tensor</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">has_onsite_density_matrices</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="s2">&quot;has_onsite_density_matrices&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;onsite density matrix&quot;</span><span class="p">},</span>
                          <span class="n">terminate_on_match</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">if</span> <span class="s2">&quot;has_onsite_density_matrices&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">has_onsite_density_matrices</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">read_onsite_density_matrices</span><span class="p">()</span>

        <span class="c1"># Store the individual contributions to the final total energy</span>
        <span class="n">final_energy_contribs</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;PSCENC&quot;</span><span class="p">,</span> <span class="s2">&quot;TEWEN&quot;</span><span class="p">,</span> <span class="s2">&quot;DENC&quot;</span><span class="p">,</span> <span class="s2">&quot;EXHF&quot;</span><span class="p">,</span> <span class="s2">&quot;XCENC&quot;</span><span class="p">,</span> <span class="s2">&quot;PAW double counting&quot;</span><span class="p">,</span>
                  <span class="s2">&quot;EENTRO&quot;</span><span class="p">,</span> <span class="s2">&quot;EBANDS&quot;</span><span class="p">,</span> <span class="s2">&quot;EATOM&quot;</span><span class="p">,</span> <span class="s2">&quot;Ediel_sol&quot;</span><span class="p">]:</span>
            <span class="k">if</span> <span class="n">k</span> <span class="o">==</span> <span class="s2">&quot;PAW double counting&quot;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">\s+=\s+([\.\-\d]+)\s+([\.\-\d]+)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">)})</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">\s+=\s+([\d\-\.]+)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">)})</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]:</span>
                <span class="k">continue</span>
            <span class="n">final_energy_contribs</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">final_energy_contribs</span> <span class="o">=</span> <span class="n">final_energy_contribs</span>

<div class="viewcode-block" id="Outcar.read_pattern"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_pattern">[docs]</a>    <span class="k">def</span> <span class="nf">read_pattern</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">terminate_on_match</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                     <span class="n">postprocess</span><span class="o">=</span><span class="nb">str</span><span class="p">):</span>
        <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        General pattern reading. Uses monty&#39;s regrep method. Takes the same</span>
<span class="sd">        arguments.</span>

<span class="sd">        Args:</span>
<span class="sd">            patterns (dict): A dict of patterns, e.g.,</span>
<span class="sd">                {&quot;energy&quot;: r&quot;energy\\(sigma-&gt;0\\)\\s+=\\s+([\\d\\-.]+)&quot;}.</span>
<span class="sd">            reverse (bool): Read files in reverse. Defaults to false. Useful for</span>
<span class="sd">                large files, esp OUTCARs, especially when used with</span>
<span class="sd">                terminate_on_match.</span>
<span class="sd">            terminate_on_match (bool): Whether to terminate when there is at</span>
<span class="sd">                least one match in each key in pattern.</span>
<span class="sd">            postprocess (callable): A post processing function to convert all</span>
<span class="sd">                matches. Defaults to str, i.e., no change.</span>

<span class="sd">        Renders accessible:</span>
<span class="sd">            Any attribute in patterns. For example,</span>
<span class="sd">            {&quot;energy&quot;: r&quot;energy\\(sigma-&gt;0\\)\\s+=\\s+([\\d\\-.]+)&quot;} will set the</span>
<span class="sd">            value of self.data[&quot;energy&quot;] = [[-1234], [-3453], ...], to the</span>
<span class="sd">            results from regex and postprocess. Note that the returned values</span>
<span class="sd">            are lists of lists, because you can grep multiple items on one line.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">matches</span> <span class="o">=</span> <span class="n">regrep</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="n">reverse</span><span class="p">,</span>
                         <span class="n">terminate_on_match</span><span class="o">=</span><span class="n">terminate_on_match</span><span class="p">,</span>
                         <span class="n">postprocess</span><span class="o">=</span><span class="n">postprocess</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">patterns</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">matches</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="p">[])]</span></div>

<div class="viewcode-block" id="Outcar.read_table_pattern"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_table_pattern">[docs]</a>    <span class="k">def</span> <span class="nf">read_table_pattern</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span> <span class="n">footer_pattern</span><span class="p">,</span>
                           <span class="n">postprocess</span><span class="o">=</span><span class="nb">str</span><span class="p">,</span> <span class="n">attribute_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                           <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse table-like data. A table composes of three parts: header,</span>
<span class="sd">        main body, footer. All the data matches &quot;row pattern&quot; in the main body</span>
<span class="sd">        will be returned.</span>

<span class="sd">        Args:</span>
<span class="sd">            header_pattern (str): The regular expression pattern matches the</span>
<span class="sd">                table header. This pattern should match all the text</span>
<span class="sd">                immediately before the main body of the table. For multiple</span>
<span class="sd">                sections table match the text until the section of</span>
<span class="sd">                interest. MULTILINE and DOTALL options are enforced, as a</span>
<span class="sd">                result, the &quot;.&quot; meta-character will also match &quot;\n&quot; in this</span>
<span class="sd">                section.</span>
<span class="sd">            row_pattern (str): The regular expression matches a single line in</span>
<span class="sd">                the table. Capture interested field using regular expression</span>
<span class="sd">                groups.</span>
<span class="sd">            footer_pattern (str): The regular expression matches the end of the</span>
<span class="sd">                table. E.g. a long dash line.</span>
<span class="sd">            postprocess (callable): A post processing function to convert all</span>
<span class="sd">                matches. Defaults to str, i.e., no change.</span>
<span class="sd">            attribute_name (str): Name of this table. If present the parsed data</span>
<span class="sd">                will be attached to &quot;data. e.g. self.data[&quot;efg&quot;] = [...]</span>
<span class="sd">            last_one_only (bool): All the tables will be parsed, if this option</span>
<span class="sd">                is set to True, only the last table will be returned. The</span>
<span class="sd">                enclosing list will be removed. i.e. Only a single table will</span>
<span class="sd">                be returned. Default to be True.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of tables. 1) A table is a list of rows. 2) A row if either a list of</span>
<span class="sd">            attribute values in case the the capturing group is defined without name in</span>
<span class="sd">            row_pattern, or a dict in case that named capturing groups are defined by</span>
<span class="sd">            row_pattern.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;rt&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">text</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
        <span class="n">table_pattern_text</span> <span class="o">=</span> <span class="n">header_pattern</span> <span class="o">+</span> <span class="sa">r</span><span class="s2">&quot;\s*^(?P&lt;table_body&gt;(?:\s+&quot;</span> <span class="o">+</span> <span class="n">row_pattern</span> <span class="o">+</span> <span class="sa">r</span><span class="s2">&quot;)+)\s+&quot;</span> <span class="o">+</span> <span class="n">footer_pattern</span>
        <span class="n">table_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">table_pattern_text</span><span class="p">,</span> <span class="n">re</span><span class="o">.</span><span class="n">MULTILINE</span> <span class="o">|</span> <span class="n">re</span><span class="o">.</span><span class="n">DOTALL</span><span class="p">)</span>
        <span class="n">rp</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">row_pattern</span><span class="p">)</span>
        <span class="n">tables</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">mt</span> <span class="ow">in</span> <span class="n">table_pattern</span><span class="o">.</span><span class="n">finditer</span><span class="p">(</span><span class="n">text</span><span class="p">):</span>
            <span class="n">table_body_text</span> <span class="o">=</span> <span class="n">mt</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s2">&quot;table_body&quot;</span><span class="p">)</span>
            <span class="n">table_contents</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">table_body_text</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">):</span>
                <span class="n">ml</span> <span class="o">=</span> <span class="n">rp</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                <span class="c1"># skip empty lines</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">ml</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="n">d</span> <span class="o">=</span> <span class="n">ml</span><span class="o">.</span><span class="n">groupdict</span><span class="p">()</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">processed_line</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">postprocess</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">processed_line</span> <span class="o">=</span> <span class="p">[</span><span class="n">postprocess</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">ml</span><span class="o">.</span><span class="n">groups</span><span class="p">()]</span>
                <span class="n">table_contents</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">processed_line</span><span class="p">)</span>
            <span class="n">tables</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">table_contents</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">last_one_only</span><span class="p">:</span>
            <span class="n">retained_data</span> <span class="o">=</span> <span class="n">tables</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">retained_data</span> <span class="o">=</span> <span class="n">tables</span>
        <span class="k">if</span> <span class="n">attribute_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">attribute_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">retained_data</span>
        <span class="k">return</span> <span class="n">retained_data</span></div>

<div class="viewcode-block" id="Outcar.read_electrostatic_potential"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_electrostatic_potential">[docs]</a>    <span class="k">def</span> <span class="nf">read_electrostatic_potential</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses the eletrostatic potential for the last ionic step</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">pattern</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;ngf&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;\s+dimension x,y,z NGXF=\s+([\.\-\d]+)\sNGYF=\s+([\.\-\d]+)\sNGZF=\s+([\.\-\d]+)&quot;</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">(</span><span class="n">pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">int</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ngf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;ngf&quot;</span><span class="p">,</span> <span class="p">[[]])[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">pattern</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;radii&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;the test charge radii are((?:\s+[\.\-\d]+)+)&quot;</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">(</span><span class="n">pattern</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">terminate_on_match</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sampling_radii</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;radii&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>

        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\(the norm of the test charge is\s+[\.\-\d]+\)&quot;</span>
        <span class="n">table_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;((?:\s+\d+\s*[\.\-\d]+)+)&quot;</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s+E-fermi :&quot;</span>

        <span class="n">pots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">table_pattern</span><span class="p">,</span> <span class="n">footer_pattern</span><span class="p">)</span>
        <span class="n">pots</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="o">.</span><span class="n">from_iterable</span><span class="p">(</span><span class="n">pots</span><span class="p">))</span>

        <span class="n">pots</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\s+\d+\s*([\.\-\d]+)+&quot;</span><span class="p">,</span> <span class="n">pots</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">electrostatic_potential</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">pots</span><span class="p">]</span></div>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_parse_sci_notation</span><span class="p">(</span><span class="n">line</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method to parse lines with values in scientific notation and potentially</span>
<span class="sd">        without spaces in between the values. This assumes that the scientific</span>
<span class="sd">        notation always lists two digits for the exponent, e.g. 3.535E-02</span>
<span class="sd">        Args:</span>
<span class="sd">            line: line to parse</span>

<span class="sd">        Returns: an array of numbers if found, or empty array if not</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;[\.\-\d]+E[\+\-]\d</span><span class="si">{2}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">m</span><span class="p">]</span>
        <span class="k">return</span> <span class="p">[]</span>

<div class="viewcode-block" id="Outcar.read_freq_dielectric"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_freq_dielectric">[docs]</a>    <span class="k">def</span> <span class="nf">read_freq_dielectric</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses the frequency dependent dielectric function (obtained with</span>
<span class="sd">        LOPTICS). Frequencies (in eV) are in self.frequencies, and dielectric</span>
<span class="sd">        tensor function is given as self.dielectric_tensor_function.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">plasma_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;plasma frequency squared.*&quot;</span>
        <span class="n">dielectric_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;frequency dependent\s+IMAGINARY &quot;</span> \
                             <span class="sa">r</span><span class="s2">&quot;DIELECTRIC FUNCTION \(independent particle, &quot;</span> \
                             <span class="sa">r</span><span class="s2">&quot;no local field effects\)(\sdensity-density)*$&quot;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;([\.\-\d]+)&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span><span class="p">)</span>
        <span class="n">plasma_frequencies</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
        <span class="n">read_plasma</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">read_dielectric</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">energies</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;REAL&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;IMAGINARY&quot;</span><span class="p">:</span> <span class="p">[]}</span>
        <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">component</span> <span class="o">=</span> <span class="s2">&quot;IMAGINARY&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">l</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">plasma_pattern</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
                    <span class="n">read_plasma</span> <span class="o">=</span> <span class="s2">&quot;intraband&quot;</span> <span class="k">if</span> <span class="s2">&quot;intraband&quot;</span> <span class="ow">in</span> <span class="n">l</span> <span class="k">else</span> <span class="s2">&quot;interband&quot;</span>
                <span class="k">elif</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">dielectric_pattern</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
                    <span class="n">read_plasma</span> <span class="o">=</span> <span class="kc">False</span>
                    <span class="n">read_dielectric</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;([\.\-\d]+)&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">7</span><span class="p">)</span>

                <span class="k">if</span> <span class="n">read_plasma</span> <span class="ow">and</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">row_pattern</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
                    <span class="n">plasma_frequencies</span><span class="p">[</span><span class="n">read_plasma</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()])</span>
                <span class="k">elif</span> <span class="n">read_plasma</span> <span class="ow">and</span> <span class="n">Outcar</span><span class="o">.</span><span class="n">_parse_sci_notation</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
                    <span class="n">plasma_frequencies</span><span class="p">[</span><span class="n">read_plasma</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="n">Outcar</span><span class="o">.</span><span class="n">_parse_sci_notation</span><span class="p">(</span><span class="n">l</span><span class="p">))</span>
                <span class="k">elif</span> <span class="n">read_dielectric</span><span class="p">:</span>
                    <span class="n">toks</span> <span class="o">=</span> <span class="kc">None</span>
                    <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">row_pattern</span><span class="p">,</span> <span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()):</span>
                        <span class="n">toks</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="k">elif</span> <span class="n">Outcar</span><span class="o">.</span><span class="n">_parse_sci_notation</span><span class="p">(</span><span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()):</span>
                        <span class="n">toks</span> <span class="o">=</span> <span class="n">Outcar</span><span class="o">.</span><span class="n">_parse_sci_notation</span><span class="p">(</span><span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
                    <span class="k">elif</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\s*-+\s*&quot;</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
                        <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>

                    <span class="k">if</span> <span class="n">toks</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">component</span> <span class="o">==</span> <span class="s2">&quot;IMAGINARY&quot;</span><span class="p">:</span>
                            <span class="n">energies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">toks</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
                        <span class="n">xx</span><span class="p">,</span> <span class="n">yy</span><span class="p">,</span> <span class="n">zz</span><span class="p">,</span> <span class="n">xy</span><span class="p">,</span> <span class="n">yz</span><span class="p">,</span> <span class="n">xz</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">[</span><span class="mi">1</span><span class="p">:]]</span>
                        <span class="n">matrix</span> <span class="o">=</span> <span class="p">[[</span><span class="n">xx</span><span class="p">,</span> <span class="n">xy</span><span class="p">,</span> <span class="n">xz</span><span class="p">],</span> <span class="p">[</span><span class="n">xy</span><span class="p">,</span> <span class="n">yy</span><span class="p">,</span> <span class="n">yz</span><span class="p">],</span> <span class="p">[</span><span class="n">xz</span><span class="p">,</span> <span class="n">yz</span><span class="p">,</span> <span class="n">zz</span><span class="p">]]</span>
                        <span class="n">data</span><span class="p">[</span><span class="n">component</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">matrix</span><span class="p">)</span>

                    <span class="k">if</span> <span class="n">count</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                        <span class="n">component</span> <span class="o">=</span> <span class="s2">&quot;REAL&quot;</span>
                    <span class="k">elif</span> <span class="n">count</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                        <span class="k">break</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">plasma_frequencies</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">[:</span><span class="mi">3</span><span class="p">])</span>
                                   <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">plasma_frequencies</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_energies</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">energies</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_tensor_function</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;REAL&quot;</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span><span class="n">j</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;IMAGINARY&quot;</span><span class="p">])</span></div>

    <span class="nd">@property</span>  <span class="c1"># type: ignore</span>
    <span class="nd">@deprecated</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s2">&quot;frequencies has been renamed to dielectric_energies.&quot;</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">frequencies</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Renamed to dielectric energies.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_energies</span>

<div class="viewcode-block" id="Outcar.read_chemical_shielding"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_chemical_shielding">[docs]</a>    <span class="k">def</span> <span class="nf">read_chemical_shielding</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the NMR chemical shieldings data. Only the second part &quot;absolute, valence and core&quot;</span>
<span class="sd">        will be parsed. And only the three right most field (ISO_SHIELDING, SPAN, SKEW) will be retrieved.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of chemical shieldings in the order of atoms from the OUTCAR. Maryland notation is adopted.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s+CSA tensor \(J\. Mason, Solid State Nucl\. Magn\. Reson\. 2, &quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;285 \(1993\)\)\s+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;\s+-{50,}\s+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;\s+EXCLUDING G=0 CONTRIBUTION\s+INCLUDING G=0 CONTRIBUTION\s+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;\s+-{20,}\s+-{20,}\s+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;\s+ATOM\s+ISO_SHIFT\s+SPAN\s+SKEW\s+ISO_SHIFT\s+SPAN\s+SKEW\s+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;-{50,}\s*$&quot;</span>
        <span class="n">first_part_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s+\(absolute, valence only\)\s+$&quot;</span>
        <span class="n">swallon_valence_body_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;.+?\(absolute, valence and core\)\s+$&quot;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\d+(?:\s+[-]?\d+\.\d+)</span><span class="si">{3}</span><span class="s2">\s+&quot;</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;\s+&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
            <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;([-]?\d+\.\d+)&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span><span class="p">)</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;-{50,}\s*$&quot;</span>
        <span class="n">h1</span> <span class="o">=</span> <span class="n">header_pattern</span> <span class="o">+</span> <span class="n">first_part_pattern</span>
        <span class="n">cs_valence_only</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span>
            <span class="n">h1</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span> <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span>
            <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">h2</span> <span class="o">=</span> <span class="n">header_pattern</span> <span class="o">+</span> <span class="n">swallon_valence_body_pattern</span>
        <span class="n">cs_valence_and_core</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span>
            <span class="n">h2</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span> <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span>
            <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">all_cs</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">cs_table</span> <span class="ow">in</span> <span class="p">[[</span><span class="s2">&quot;valence_only&quot;</span><span class="p">,</span> <span class="n">cs_valence_only</span><span class="p">],</span>
                               <span class="p">[</span><span class="s2">&quot;valence_and_core&quot;</span><span class="p">,</span> <span class="n">cs_valence_and_core</span><span class="p">]]:</span>
            <span class="n">all_cs</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">cs_table</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;chemical_shielding&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">all_cs</span></div>

<div class="viewcode-block" id="Outcar.read_cs_g0_contribution"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_cs_g0_contribution">[docs]</a>    <span class="k">def</span> <span class="nf">read_cs_g0_contribution</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the  G0 contribution of NMR chemical shielding.</span>

<span class="sd">        Returns:</span>
<span class="sd">            G0 contribution matrix as list of list.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;^\s+G\=0 CONTRIBUTION TO CHEMICAL SHIFT \(field along BDIR\)\s+$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+-{50,}$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+BDIR\s+X\s+Y\s+Z\s*$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+-{50,}\s*$\n&#39;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;(?:\d+)\s+&#39;</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;\s+&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s1">&#39;([-]?\d+\.\d+)&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span><span class="p">)</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;\s+-{50,}\s*$&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span> <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span>
                                <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">attribute_name</span><span class="o">=</span><span class="s2">&quot;cs_g0_contribution&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_cs_core_contribution"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_cs_core_contribution">[docs]</a>    <span class="k">def</span> <span class="nf">read_cs_core_contribution</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Parse the core contribution of NMR chemical shielding.</span>

<span class="sd">            Returns:</span>
<span class="sd">            G0 contribution matrix as list of list.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;^\s+Core NMR properties\s*$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+typ\s+El\s+Core shift \(ppm\)\s*$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+-{20,}$\n&#39;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;\d+\s+(?P&lt;element&gt;[A-Z][a-z]?\w?)\s+(?P&lt;shift&gt;[-]?\d+\.\d+)&#39;</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;\s+-{20,}\s*$&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span> <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">str</span><span class="p">,</span>
                                <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">attribute_name</span><span class="o">=</span><span class="s2">&quot;cs_core_contribution&quot;</span><span class="p">)</span>
        <span class="n">core_contrib</span> <span class="o">=</span> <span class="p">{</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;element&#39;</span><span class="p">]:</span> <span class="nb">float</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;shift&#39;</span><span class="p">])</span>
                        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;cs_core_contribution&quot;</span><span class="p">]}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;cs_core_contribution&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">core_contrib</span></div>

<div class="viewcode-block" id="Outcar.read_cs_raw_symmetrized_tensors"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_cs_raw_symmetrized_tensors">[docs]</a>    <span class="k">def</span> <span class="nf">read_cs_raw_symmetrized_tensors</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the matrix form of NMR tensor before corrected to table.</span>

<span class="sd">        Returns:</span>
<span class="sd">            nsymmetrized tensors list in the order of atoms.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s+-{50,}\s+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;\s+Absolute Chemical Shift tensors\s+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;\s+-{50,}$&quot;</span>
        <span class="n">first_part_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s+UNSYMMETRIZED TENSORS\s+$&quot;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;([-]?\d+\.\d+)&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span><span class="p">)</span>
        <span class="n">unsym_footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;^\s+SYMMETRIZED TENSORS\s+$&quot;</span>

        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;rt&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">text</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
        <span class="n">unsym_table_pattern_text</span> <span class="o">=</span> <span class="n">header_pattern</span> <span class="o">+</span> <span class="n">first_part_pattern</span> <span class="o">+</span> <span class="sa">r</span><span class="s2">&quot;(?P&lt;table_body&gt;.+)&quot;</span> <span class="o">+</span> <span class="n">unsym_footer_pattern</span>
        <span class="n">table_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">unsym_table_pattern_text</span><span class="p">,</span> <span class="n">re</span><span class="o">.</span><span class="n">MULTILINE</span> <span class="o">|</span> <span class="n">re</span><span class="o">.</span><span class="n">DOTALL</span><span class="p">)</span>
        <span class="n">rp</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">row_pattern</span><span class="p">)</span>
        <span class="n">m</span> <span class="o">=</span> <span class="n">table_pattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
            <span class="n">table_text</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s2">&quot;table_body&quot;</span><span class="p">)</span>
            <span class="n">micro_header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;ion\s+\d+&quot;</span>
            <span class="n">micro_table_pattern_text</span> <span class="o">=</span> <span class="n">micro_header_pattern</span> <span class="o">+</span> <span class="sa">r</span><span class="s2">&quot;\s*^(?P&lt;table_body&gt;(?:\s*&quot;</span> <span class="o">+</span> <span class="n">row_pattern</span> <span class="o">+</span> <span class="sa">r</span><span class="s2">&quot;)+)\s+&quot;</span>
            <span class="n">micro_table_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">micro_table_pattern_text</span><span class="p">,</span>
                                             <span class="n">re</span><span class="o">.</span><span class="n">MULTILINE</span> <span class="o">|</span> <span class="n">re</span><span class="o">.</span><span class="n">DOTALL</span><span class="p">)</span>
            <span class="n">unsym_tensors</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">mt</span> <span class="ow">in</span> <span class="n">micro_table_pattern</span><span class="o">.</span><span class="n">finditer</span><span class="p">(</span><span class="n">table_text</span><span class="p">):</span>
                <span class="n">table_body_text</span> <span class="o">=</span> <span class="n">mt</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s2">&quot;table_body&quot;</span><span class="p">)</span>
                <span class="n">tensor_matrix</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">table_body_text</span><span class="o">.</span><span class="n">rstrip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">):</span>
                    <span class="n">ml</span> <span class="o">=</span> <span class="n">rp</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                    <span class="n">processed_line</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">ml</span><span class="o">.</span><span class="n">groups</span><span class="p">()]</span>
                    <span class="n">tensor_matrix</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">processed_line</span><span class="p">)</span>
                <span class="n">unsym_tensors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tensor_matrix</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;unsym_cs_tensor&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">unsym_tensors</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;NMR UNSYMMETRIZED TENSORS is not found&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_nmr_efg_tensor"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_nmr_efg_tensor">[docs]</a>    <span class="k">def</span> <span class="nf">read_nmr_efg_tensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses the NMR Electric Field Gradient Raw Tensors</span>

<span class="sd">        Returns:</span>
<span class="sd">            A list of Electric Field Gradient Tensors in the order of Atoms from OUTCAR</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;Electric field gradients \(V/A\^2\)\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;-*\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39; ion\s+V_xx\s+V_yy\s+V_zz\s+V_xy\s+V_xz\s+V_yz\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;-*\n&#39;</span>

        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;\d+\s+([-\d\.]+)\s+([-\d\.]+)\s+([-\d\.]+)\s+([-\d\.]+)\s+([-\d\.]+)\s+([-\d\.]+)&#39;</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;-*\n&#39;</span>

        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span> <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
        <span class="n">tensors</span> <span class="o">=</span> <span class="p">[</span><span class="n">make_symmetric_matrix_from_upper_tri</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;unsym_efg_tensor&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">tensors</span>
        <span class="k">return</span> <span class="n">tensors</span></div>

<div class="viewcode-block" id="Outcar.read_nmr_efg"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_nmr_efg">[docs]</a>    <span class="k">def</span> <span class="nf">read_nmr_efg</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the NMR Electric Field Gradient interpretted values.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Electric Field Gradient tensors as a list of dict in the order of atoms from OUTCAR.</span>
<span class="sd">            Each dict key/value pair corresponds to a component of the tensors.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;^\s+NMR quadrupolar parameters\s+$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+Cq : quadrupolar parameter\s+Cq=e[*]Q[*]V_zz/h$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+eta: asymmetry parameters\s+\(V_yy - V_xx\)/ V_zz$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+Q  : nuclear electric quadrupole moment in mb \(millibarn\)$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^-{50,}$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^\s+ion\s+Cq\(MHz\)\s+eta\s+Q \(mb\)\s+$\n&#39;</span> \
                         <span class="sa">r</span><span class="s1">&#39;^-{50,}\s*$\n&#39;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;\d+\s+(?P&lt;cq&gt;[-]?\d+\.\d+)\s+(?P&lt;eta&gt;[-]?\d+\.\d+)\s+&#39;</span> \
                      <span class="sa">r</span><span class="s1">&#39;(?P&lt;nuclear_quadrupole_moment&gt;[-]?\d+\.\d+)&#39;</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;-{50,}\s*$&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span> <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span>
                                <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">attribute_name</span><span class="o">=</span><span class="s2">&quot;efg&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_elastic_tensor"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_elastic_tensor">[docs]</a>    <span class="k">def</span> <span class="nf">read_elastic_tensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the elastic tensor data.</span>

<span class="sd">        Returns:</span>
<span class="sd">            6x6 array corresponding to the elastic tensor from the OUTCAR.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;TOTAL ELASTIC MODULI \(kBar\)\s+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;Direction\s+([X-Z][X-Z]\s+)+&quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;\-+&quot;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;[X-Z][X-Z]\s+&quot;</span> <span class="o">+</span> <span class="sa">r</span><span class="s2">&quot;\s+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;(\-*[\.\d]+)&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">6</span><span class="p">)</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\-+&quot;</span>
        <span class="n">et_table</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span>
                                           <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;elastic_tensor&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">et_table</span></div>

<div class="viewcode-block" id="Outcar.read_piezo_tensor"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_piezo_tensor">[docs]</a>    <span class="k">def</span> <span class="nf">read_piezo_tensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the piezo tensor data</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;PIEZOELECTRIC TENSOR  for field in x, y, &quot;</span> \
                         <span class="sa">r</span><span class="s2">&quot;z\s+\(C/m\^2\)\s+([X-Z][X-Z]\s+)+\-+&quot;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;[x-z]\s+&quot;</span> <span class="o">+</span> <span class="sa">r</span><span class="s2">&quot;\s+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;(\-*[\.\d]+)&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">6</span><span class="p">)</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;BORN EFFECTIVE&quot;</span>
        <span class="n">pt_table</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span>
                                           <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;piezo_tensor&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pt_table</span></div>

<div class="viewcode-block" id="Outcar.read_onsite_density_matrices"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_onsite_density_matrices">[docs]</a>    <span class="k">def</span> <span class="nf">read_onsite_density_matrices</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parse the onsite density matrices, returns list with index corresponding</span>
<span class="sd">        to atom index in Structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># matrix size will vary depending on if d or f orbitals are present</span>
        <span class="c1"># therefore regex assumes f, but filter out None values if d</span>

        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;spin component  1\n&quot;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;[^\S\r\n]*(?:(-?[\d.]+))&#39;</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;(?:[^\S\r\n]*(-?[\d.]+)[^\S\r\n]*)?&#39;</span> <span class="o">*</span> <span class="mi">6</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;.*?&#39;</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\nspin component  2&quot;</span>
        <span class="n">spin1_component</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span>
                                                  <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">if</span> <span class="n">x</span> <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                                                  <span class="n">last_one_only</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

        <span class="c1"># filter out None values</span>
        <span class="n">spin1_component</span> <span class="o">=</span> <span class="p">[[[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">row</span> <span class="k">if</span> <span class="n">e</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">]</span> <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">matrix</span><span class="p">]</span> <span class="k">for</span> <span class="n">matrix</span> <span class="ow">in</span> <span class="n">spin1_component</span><span class="p">]</span>

        <span class="c1"># and repeat for Spin.down</span>

        <span class="n">header_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;spin component  2\n&quot;</span>
        <span class="n">row_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;[^\S\r\n]*(?:([\d.-]+))&#39;</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;(?:[^\S\r\n]*(-?[\d.]+)[^\S\r\n]*)?&#39;</span> <span class="o">*</span> <span class="mi">6</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;.*?&#39;</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\n occupancies and eigenvectors&quot;</span>
        <span class="n">spin2_component</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern</span><span class="p">,</span> <span class="n">row_pattern</span><span class="p">,</span>
                                                  <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">if</span> <span class="n">x</span> <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                                                  <span class="n">last_one_only</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

        <span class="n">spin2_component</span> <span class="o">=</span> <span class="p">[[[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">row</span> <span class="k">if</span> <span class="n">e</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">]</span> <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">matrix</span><span class="p">]</span> <span class="k">for</span> <span class="n">matrix</span> <span class="ow">in</span> <span class="n">spin2_component</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;onsite_density_matrices&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span>
            <span class="p">{</span>
                <span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="n">spin1_component</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span>
                <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">:</span> <span class="n">spin2_component</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span>
            <span class="p">}</span>
            <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">spin1_component</span><span class="p">))</span>
        <span class="p">]</span></div>

<div class="viewcode-block" id="Outcar.read_corrections"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_corrections">[docs]</a>    <span class="k">def</span> <span class="nf">read_corrections</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">terminate_on_match</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads the dipol qudropol corrections into the</span>
<span class="sd">        Outcar.data[&quot;dipol_quadrupol_correction&quot;].</span>

<span class="sd">        :param reverse: Whether to start from end of OUTCAR.</span>
<span class="sd">        :param terminate_on_match: Whether to terminate once match is found.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">patterns</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;dipol_quadrupol_correction&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;dipol\+quadrupol energy &quot;</span>
                                          <span class="sa">r</span><span class="s2">&quot;correction\s+([\d\-\.]+)&quot;</span>
        <span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">(</span><span class="n">patterns</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="n">reverse</span><span class="p">,</span>
                          <span class="n">terminate_on_match</span><span class="o">=</span><span class="n">terminate_on_match</span><span class="p">,</span>
                          <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;dipol_quadrupol_correction&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;dipol_quadrupol_correction&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="Outcar.read_neb"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_neb">[docs]</a>    <span class="k">def</span> <span class="nf">read_neb</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">terminate_on_match</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads NEB data. This only works with OUTCARs from both normal</span>
<span class="sd">        VASP NEB calculations or from the CI NEB method implemented by</span>
<span class="sd">        Henkelman et al.</span>

<span class="sd">        Args:</span>
<span class="sd">            reverse (bool): Read files in reverse. Defaults to false. Useful for</span>
<span class="sd">                large files, esp OUTCARs, especially when used with</span>
<span class="sd">                terminate_on_match. Defaults to True here since we usually</span>
<span class="sd">                want only the final value.</span>
<span class="sd">            terminate_on_match (bool): Whether to terminate when there is at</span>
<span class="sd">                least one match in each key in pattern. Defaults to True here</span>
<span class="sd">                since we usually want only the final value.</span>

<span class="sd">        Renders accessible:</span>
<span class="sd">            tangent_force - Final tangent force.</span>
<span class="sd">            energy - Final energy.</span>
<span class="sd">            These can be accessed under Outcar.data[key]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">patterns</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;energy&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;energy\(sigma-&gt;0\)\s+=\s+([\d\-\.]+)&quot;</span><span class="p">,</span>
            <span class="s2">&quot;tangent_force&quot;</span><span class="p">:</span> <span class="sa">r</span><span class="s2">&quot;(NEB: projections on to tangent \(spring, REAL\)\s+\S+|tangential force \(eV/A\))\s+&quot;</span>
                             <span class="sa">r</span><span class="s2">&quot;([\d\-\.]+)&quot;</span>
        <span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">read_pattern</span><span class="p">(</span><span class="n">patterns</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="n">reverse</span><span class="p">,</span>
                          <span class="n">terminate_on_match</span><span class="o">=</span><span class="n">terminate_on_match</span><span class="p">,</span>
                          <span class="n">postprocess</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;tangent_force&quot;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;tangent_force&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;tangent_force&quot;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span></div>

<div class="viewcode-block" id="Outcar.read_igpar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_igpar">[docs]</a>    <span class="k">def</span> <span class="nf">read_igpar</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Renders accessible:</span>
<span class="sd">            er_ev = e&lt;r&gt;_ev (dictionary with Spin.up/Spin.down as keys)</span>
<span class="sd">            er_bp = e&lt;r&gt;_bp (dictionary with Spin.up/Spin.down as keys)</span>
<span class="sd">            er_ev_tot = spin up + spin down summed</span>
<span class="sd">            er_bp_tot = spin up + spin down summed</span>
<span class="sd">            p_elc = spin up + spin down summed</span>
<span class="sd">            p_ion = spin up + spin down summed</span>

<span class="sd">        (See VASP section &quot;LBERRY,  IGPAR,  NPPSTR,  DIPOL tags&quot; for info on</span>
<span class="sd">        what these are).</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># variables to be filled</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">er_ev</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c1"># will  be  dict (Spin.up/down) of array(3*float)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">er_bp</span> <span class="o">=</span> <span class="p">{}</span>  <span class="c1"># will  be  dics (Spin.up/down) of array(3*float)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">er_ev_tot</span> <span class="o">=</span> <span class="kc">None</span>  <span class="c1"># will be array(3*float)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">er_bp_tot</span> <span class="o">=</span> <span class="kc">None</span>  <span class="c1"># will be array(3*float)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">p_elec</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">p_ion</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">search</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="c1"># Nonspin cases</span>
            <span class="k">def</span> <span class="nf">er_ev</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span>
                                                      <span class="n">match</span><span class="o">.</span><span class="n">groups</span><span class="p">()[</span><span class="mi">1</span><span class="p">:</span><span class="mi">4</span><span class="p">]))</span> <span class="o">/</span> <span class="mi">2</span>
                <span class="n">results</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">results</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>
                <span class="n">results</span><span class="o">.</span><span class="n">context</span> <span class="o">=</span> <span class="mi">2</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^ *e&lt;r&gt;_ev=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                           <span class="kc">None</span><span class="p">,</span> <span class="n">er_ev</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">er_bp</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
                                                   <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)])</span> <span class="o">/</span> <span class="mi">2</span>
                <span class="n">results</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">results</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^ *e&lt;r&gt;_bp=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                           <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">context</span> <span class="o">==</span> <span class="mi">2</span><span class="p">,</span> <span class="n">er_bp</span><span class="p">])</span>

            <span class="c1"># Spin cases</span>
            <span class="k">def</span> <span class="nf">er_ev_up</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
                                                   <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)])</span>
                <span class="n">results</span><span class="o">.</span><span class="n">context</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^.*Spin component 1 *e&lt;r&gt;_ev=\( *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                           <span class="kc">None</span><span class="p">,</span> <span class="n">er_ev_up</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">er_bp_up</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span>
                                                   <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                                   <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">))])</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^ *e&lt;r&gt;_bp=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                           <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">context</span> <span class="o">==</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">,</span> <span class="n">er_bp_up</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">er_ev_dn</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span>
                                                     <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                                     <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">))])</span>
                <span class="n">results</span><span class="o">.</span><span class="n">context</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^.*Spin component 2 *e&lt;r&gt;_ev=\( *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                           <span class="kc">None</span><span class="p">,</span> <span class="n">er_ev_dn</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">er_bp_dn</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
                                                     <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)])</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^ *e&lt;r&gt;_bp=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                           <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">context</span> <span class="o">==</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">,</span> <span class="n">er_bp_dn</span><span class="p">])</span>

            <span class="c1"># Always present spin/non-spin</span>
            <span class="k">def</span> <span class="nf">p_elc</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">p_elc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)])</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^.*Total electronic dipole moment: &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*p\[elc\]=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">p_elc</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">p_ion</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">p_ion</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)])</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^.*ionic dipole moment: &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*p\[ion\]=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">p_ion</span><span class="p">])</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">context</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">er_ev</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">er_bp</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">:</span> <span class="kc">None</span><span class="p">}</span>

            <span class="n">micro_pyawk</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">search</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">er_ev_tot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">er_ev</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">er_bp_tot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">er_bp</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span>

        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">er_ev_tot</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">er_bp_tot</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;IGPAR OUTCAR could not be parsed.&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_internal_strain_tensor"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_internal_strain_tensor">[docs]</a>    <span class="k">def</span> <span class="nf">read_internal_strain_tensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads the internal strain tensor and populates self.internal_strain_tensor with an array of voigt notation</span>
<span class="sd">            tensors for each site.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">search</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">def</span> <span class="nf">internal_strain_start</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
            <span class="n">results</span><span class="o">.</span><span class="n">internal_strain_ion</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> <span class="o">-</span> <span class="mi">1</span>
            <span class="n">results</span><span class="o">.</span><span class="n">internal_strain_tensor</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">)))</span>

        <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;INTERNAL STRAIN TENSOR FOR ION\s+(\d+)\s+for displacements in x,y,z  \(eV/Angst\):&quot;</span><span class="p">,</span>
                       <span class="kc">None</span><span class="p">,</span> <span class="n">internal_strain_start</span><span class="p">])</span>

        <span class="k">def</span> <span class="nf">internal_strain_data</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;x&quot;</span><span class="p">:</span>
                <span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">elif</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;y&quot;</span><span class="p">:</span>
                <span class="n">index</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">elif</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;z&quot;</span><span class="p">:</span>
                <span class="n">index</span> <span class="o">=</span> <span class="mi">2</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span>
                    <span class="s2">&quot;Couldn&#39;t parse row index from symbol for internal strain tensor: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)))</span>
            <span class="n">results</span><span class="o">.</span><span class="n">internal_strain_tensor</span><span class="p">[</span><span class="n">results</span><span class="o">.</span><span class="n">internal_strain_ion</span><span class="p">][</span><span class="n">index</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
                                                                                           <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">)])</span>
            <span class="k">if</span> <span class="n">index</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">results</span><span class="o">.</span><span class="n">internal_strain_ion</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^\s+([x,y,z])\s+&quot;</span> <span class="o">+</span> <span class="sa">r</span><span class="s2">&quot;([-]?\d+\.\d+)\s+&quot;</span> <span class="o">*</span> <span class="mi">6</span><span class="p">,</span>
                       <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">internal_strain_ion</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">,</span>
                       <span class="n">internal_strain_data</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">internal_strain_ion</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">internal_strain_tensor</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">micro_pyawk</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">search</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_lepsilon"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_lepsilon">[docs]</a>    <span class="k">def</span> <span class="nf">read_lepsilon</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads an LEPSILON run.</span>

<span class="sd">        # TODO: Document the actual variables.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">search</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">def</span> <span class="nf">dielectric_section_start</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;MACROSCOPIC STATIC DIELECTRIC TENSOR \(&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span>
                           <span class="n">dielectric_section_start</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">dielectric_section_start2</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="o">=</span> <span class="mi">0</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;-------------------------------------&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span>
                 <span class="n">dielectric_section_start2</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">dielectric_data</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_tensor</span><span class="p">[</span><span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)])</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;^ *([-0-9.Ee+]+) +([-0-9.Ee+]+) +([-0-9.Ee+]+) *$&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="o">&gt;=</span> <span class="mi">0</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                 <span class="n">dielectric_data</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">dielectric_section_stop</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;-------------------------------------&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="o">&gt;=</span> <span class="mi">1</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                 <span class="n">dielectric_section_stop</span><span class="p">])</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_index</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>

            <span class="k">def</span> <span class="nf">piezo_section_start</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">piezo_index</span> <span class="o">=</span> <span class="mi">0</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;PIEZOELECTRIC TENSOR  for field in x, y, z        &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;\(C/m\^2\)&quot;</span><span class="p">,</span>
                           <span class="kc">None</span><span class="p">,</span> <span class="n">piezo_section_start</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">piezo_data</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">piezo_tensor</span><span class="p">[</span><span class="n">results</span><span class="o">.</span><span class="n">piezo_index</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">7</span><span class="p">)])</span>
                <span class="n">results</span><span class="o">.</span><span class="n">piezo_index</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;^ *[xyz] +([-0-9.Ee+]+) +([-0-9.Ee+]+)&quot;</span> <span class="o">+</span>
                 <span class="sa">r</span><span class="s2">&quot; +([-0-9.Ee+]+) *([-0-9.Ee+]+) +([-0-9.Ee+]+)&quot;</span> <span class="o">+</span>
                 <span class="sa">r</span><span class="s2">&quot; +([-0-9.Ee+]+)*$&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_index</span> <span class="o">&gt;=</span> <span class="mi">0</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                 <span class="n">piezo_data</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">piezo_section_stop</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">piezo_index</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;-------------------------------------&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_index</span> <span class="o">&gt;=</span> <span class="mi">1</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                 <span class="n">piezo_section_stop</span><span class="p">])</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">piezo_index</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">piezo_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">))</span>

            <span class="k">def</span> <span class="nf">born_section_start</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;BORN EFFECTIVE CHARGES &quot;</span><span class="p">,</span>
                           <span class="kc">None</span><span class="p">,</span> <span class="n">born_section_start</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">born_ion</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> <span class="o">-</span> <span class="mi">1</span>
                <span class="n">results</span><span class="o">.</span><span class="n">born</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)))</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;ion +([0-9]+)&quot;</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">,</span> <span class="n">born_ion</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">born_data</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">born</span><span class="p">[</span><span class="n">results</span><span class="o">.</span><span class="n">born_ion</span><span class="p">][</span><span class="nb">int</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">)])</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;^ *([1-3]+) +([-0-9.Ee+]+) +([-0-9.Ee+]+) +([-0-9.Ee+]+)$&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span> <span class="o">&gt;=</span> <span class="mi">0</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span><span class="p">,</span>
                 <span class="n">born_data</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">born_section_stop</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;-------------------------------------&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span> <span class="o">&gt;=</span> <span class="mi">1</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="n">results</span><span class="o">.</span><span class="n">born_ion</span><span class="p">,</span>
                 <span class="n">born_section_stop</span><span class="p">])</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">born_ion</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">born</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="n">micro_pyawk</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">search</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">born</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">born</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_tensor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_tensor</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">piezo_tensor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">piezo_tensor</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>

        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;LEPSILON OUTCAR could not be parsed.&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_lepsilon_ionic"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_lepsilon_ionic">[docs]</a>    <span class="k">def</span> <span class="nf">read_lepsilon_ionic</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads an LEPSILON run, the ionic component.</span>

<span class="sd">        # TODO: Document the actual variables.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">search</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">def</span> <span class="nf">dielectric_section_start</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;MACROSCOPIC STATIC DIELECTRIC TENSOR IONIC&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span>
                           <span class="n">dielectric_section_start</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">dielectric_section_start2</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="o">=</span> <span class="mi">0</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;-------------------------------------&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span><span class="p">,</span>
                 <span class="n">dielectric_section_start2</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">dielectric_data</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_tensor</span><span class="p">[</span><span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)])</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;^ *([-0-9.Ee+]+) +([-0-9.Ee+]+) +([-0-9.Ee+]+) *$&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="o">&gt;=</span> <span class="mi">0</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span><span class="p">,</span>
                 <span class="n">dielectric_data</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">dielectric_section_stop</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;-------------------------------------&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="o">&gt;=</span> <span class="mi">1</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="n">results</span><span class="o">.</span><span class="n">dielectric_ionic_index</span><span class="p">,</span>
                 <span class="n">dielectric_section_stop</span><span class="p">])</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_ionic_index</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_ionic_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>

            <span class="k">def</span> <span class="nf">piezo_section_start</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span> <span class="o">=</span> <span class="mi">0</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;PIEZOELECTRIC TENSOR IONIC CONTR  for field in &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;x, y, z        &quot;</span><span class="p">,</span>
                           <span class="kc">None</span><span class="p">,</span> <span class="n">piezo_section_start</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">piezo_data</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_tensor</span><span class="p">[</span><span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">7</span><span class="p">)])</span>
                <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;^ *[xyz] +([-0-9.Ee+]+) +([-0-9.Ee+]+)&quot;</span> <span class="o">+</span>
                 <span class="sa">r</span><span class="s2">&quot; +([-0-9.Ee+]+) *([-0-9.Ee+]+) +([-0-9.Ee+]+)&quot;</span> <span class="o">+</span>
                 <span class="sa">r</span><span class="s2">&quot; +([-0-9.Ee+]+)*$&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span> <span class="o">&gt;=</span> <span class="mi">0</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span><span class="p">,</span>
                 <span class="n">piezo_data</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">piezo_section_stop</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="p">[</span><span class="s2">&quot;-------------------------------------&quot;</span><span class="p">,</span>
                 <span class="k">lambda</span> <span class="n">results</span><span class="p">,</span> <span class="n">line</span><span class="p">:</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span> <span class="o">&gt;=</span> <span class="mi">1</span>
                 <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
                 <span class="k">else</span> <span class="n">results</span><span class="o">.</span><span class="n">piezo_ionic_index</span><span class="p">,</span>
                 <span class="n">piezo_section_stop</span><span class="p">])</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">piezo_ionic_index</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">piezo_ionic_tensor</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">))</span>

            <span class="n">micro_pyawk</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">search</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_ionic_tensor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_ionic_tensor</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">piezo_ionic_tensor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">piezo_ionic_tensor</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>

        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span>
                <span class="s2">&quot;ionic part of LEPSILON OUTCAR could not be parsed.&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_lcalcpol"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_lcalcpol">[docs]</a>    <span class="k">def</span> <span class="nf">read_lcalcpol</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads the lcalpol.</span>

<span class="sd">        # TODO: Document the actual variables.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">p_elec</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">p_sp1</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">p_sp2</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">p_ion</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">search</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="c1"># Always present spin/non-spin</span>
            <span class="k">def</span> <span class="nf">p_elec</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">p_elec</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span>
                                           <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                           <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">))])</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^.*Total electronic dipole moment: &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*p\[elc\]=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                           <span class="kc">None</span><span class="p">,</span> <span class="n">p_elec</span><span class="p">])</span>

            <span class="c1"># If spin-polarized (and not noncollinear)</span>
            <span class="c1"># save spin-polarized electronic values</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">noncollinear</span><span class="p">:</span>
                <span class="k">def</span> <span class="nf">p_sp1</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                    <span class="n">results</span><span class="o">.</span><span class="n">p_sp1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span>
                                              <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                              <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">))])</span>

                <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^.*p\[sp1\]=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                               <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                               <span class="kc">None</span><span class="p">,</span> <span class="n">p_sp1</span><span class="p">])</span>

                <span class="k">def</span> <span class="nf">p_sp2</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                    <span class="n">results</span><span class="o">.</span><span class="n">p_sp2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span>
                                              <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                              <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">))])</span>

                <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^.*p\[sp2\]=\( *([-0-9.Ee+]*) *([-0-9.Ee+]*) &quot;</span>
                               <span class="sa">r</span><span class="s2">&quot;*([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                               <span class="kc">None</span><span class="p">,</span> <span class="n">p_sp2</span><span class="p">])</span>

            <span class="k">def</span> <span class="nf">p_ion</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">results</span><span class="o">.</span><span class="n">p_ion</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span>
                                          <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                          <span class="nb">float</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">))])</span>

            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s2">&quot;^.*Ionic dipole moment: *p\[ion\]=&quot;</span>
                           <span class="sa">r</span><span class="s2">&quot;\( *([-0-9.Ee+]*)&quot;</span>
                           <span class="sa">r</span><span class="s2">&quot; *([-0-9.Ee+]*) *([-0-9.Ee+]*) *\)&quot;</span><span class="p">,</span>
                           <span class="kc">None</span><span class="p">,</span> <span class="n">p_ion</span><span class="p">])</span>

            <span class="n">micro_pyawk</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">search</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>

        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;LCALCPOL OUTCAR could not be parsed.&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_pseudo_zval"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_pseudo_zval">[docs]</a>    <span class="k">def</span> <span class="nf">read_pseudo_zval</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create pseudopotential ZVAL dictionary.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">def</span> <span class="nf">atom_symbols</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">element_symbol</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="s1">&#39;atom_symbols&#39;</span><span class="p">):</span>
                    <span class="n">results</span><span class="o">.</span><span class="n">atom_symbols</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">results</span><span class="o">.</span><span class="n">atom_symbols</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">element_symbol</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>

            <span class="k">def</span> <span class="nf">zvals</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
                <span class="n">zvals</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
                <span class="n">results</span><span class="o">.</span><span class="n">zvals</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;-?\d+\.\d*&#39;</span><span class="p">,</span> <span class="n">zvals</span><span class="p">))</span>

            <span class="n">search</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s1">&#39;(?&lt;=VRHFIN =)(.*)(?=:)&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">atom_symbols</span><span class="p">])</span>
            <span class="n">search</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="sa">r</span><span class="s1">&#39;^\s+ZVAL.*=(.*)&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">zvals</span><span class="p">])</span>

            <span class="n">micro_pyawk</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">search</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>

            <span class="n">zval_dict</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom_symbols</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">zvals</span><span class="p">):</span>
                <span class="n">zval_dict</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">x</span><span class="p">:</span> <span class="n">y</span><span class="p">})</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">zval_dict</span> <span class="o">=</span> <span class="n">zval_dict</span>

            <span class="c1"># Clean-up</span>
            <span class="k">del</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atom_symbols</span><span class="p">)</span>
            <span class="k">del</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zvals</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;ZVAL dict could not be parsed.&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Outcar.read_core_state_eigen"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_core_state_eigen">[docs]</a>    <span class="k">def</span> <span class="nf">read_core_state_eigen</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Read the core state eigenenergies at each ionic step.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A list of dict over the atom such as [{&quot;AO&quot;:[core state eig]}].</span>
<span class="sd">            The core state eigenenergie list for each AO is over all ionic</span>
<span class="sd">            step.</span>

<span class="sd">        Example:</span>
<span class="sd">            The core state eigenenergie of the 2s AO of the 6th atom of the</span>
<span class="sd">            structure at the last ionic step is [5][&quot;2s&quot;][-1]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">foutcar</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">foutcar</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
            <span class="k">while</span> <span class="n">line</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">foutcar</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
                <span class="k">if</span> <span class="s2">&quot;NIONS =&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">natom</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;NIONS =&quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
                    <span class="n">cl</span> <span class="o">=</span> <span class="p">[</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">natom</span><span class="p">)]</span>
                <span class="k">if</span> <span class="s2">&quot;the core state eigen&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">iat</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
                    <span class="k">while</span> <span class="n">line</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
                        <span class="n">line</span> <span class="o">=</span> <span class="n">foutcar</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
                        <span class="c1"># don&#39;t know number of lines to parse without knowing</span>
                        <span class="c1"># specific species, so stop parsing when we reach</span>
                        <span class="c1"># &quot;E-fermi&quot; instead</span>
                        <span class="k">if</span> <span class="s2">&quot;E-fermi&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                            <span class="k">break</span>
                        <span class="n">data</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                        <span class="c1"># data will contain odd number of elements if it is</span>
                        <span class="c1"># the start of a new entry, or even number of elements</span>
                        <span class="c1"># if it continues the previous entry</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                            <span class="n">iat</span> <span class="o">+=</span> <span class="mi">1</span>  <span class="c1"># started parsing a new ion</span>
                            <span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>  <span class="c1"># remove element with ion number</span>
                        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="mi">2</span><span class="p">):</span>
                            <span class="n">cl</span><span class="p">[</span><span class="n">iat</span><span class="p">][</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]))</span>
        <span class="k">return</span> <span class="n">cl</span></div>

<div class="viewcode-block" id="Outcar.read_avg_core_poten"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_avg_core_poten">[docs]</a>    <span class="k">def</span> <span class="nf">read_avg_core_poten</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Read the core potential at each ionic step.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A list for each ionic step containing a list of the average core</span>
<span class="sd">            potentials for each atom: [[avg core pot]].</span>

<span class="sd">        Example:</span>
<span class="sd">            The average core potential of the 2nd atom of the structure at the</span>
<span class="sd">            last ionic step is: [-1][1]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">def</span> <span class="nf">pairwise</span><span class="p">(</span><span class="n">iterable</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;s -&gt; (s0,s1), (s1,s2), (s2, s3), ...&quot;&quot;&quot;</span>
            <span class="n">a</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="n">iterable</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">zip</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>

        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">foutcar</span><span class="p">:</span>
            <span class="n">line</span> <span class="o">=</span> <span class="n">foutcar</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
            <span class="n">aps</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">while</span> <span class="n">line</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">foutcar</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
                <span class="k">if</span> <span class="s2">&quot;the norm of the test charge is&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                    <span class="n">ap</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">while</span> <span class="n">line</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
                        <span class="n">line</span> <span class="o">=</span> <span class="n">foutcar</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
                        <span class="c1"># don&#39;t know number of lines to parse without knowing</span>
                        <span class="c1"># specific species, so stop parsing when we reach</span>
                        <span class="c1"># &quot;E-fermi&quot; instead</span>
                        <span class="k">if</span> <span class="s2">&quot;E-fermi&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                            <span class="n">aps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ap</span><span class="p">)</span>
                            <span class="k">break</span>
                        <span class="n">data</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                        <span class="c1"># the average core potentials of up to 5 elements are</span>
                        <span class="c1"># given per line</span>
                        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">pot</span> <span class="ow">in</span> <span class="n">pairwise</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
                            <span class="n">ap</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">pot</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">aps</span></div>

<div class="viewcode-block" id="Outcar.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONAble dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
             <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
             <span class="s2">&quot;run_stats&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_stats</span><span class="p">,</span> <span class="s2">&quot;magnetization&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">magnetization</span><span class="p">,</span>
             <span class="s2">&quot;charge&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">charge</span><span class="p">,</span> <span class="s2">&quot;total_magnetization&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">total_mag</span><span class="p">,</span>
             <span class="s2">&quot;nelect&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nelect</span><span class="p">,</span> <span class="s2">&quot;is_stopped&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_stopped</span><span class="p">,</span>
             <span class="s2">&quot;drift&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">drift</span><span class="p">,</span> <span class="s2">&quot;ngf&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ngf</span><span class="p">,</span>
             <span class="s2">&quot;sampling_radii&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">sampling_radii</span><span class="p">,</span>
             <span class="s2">&quot;electrostatic_potential&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">electrostatic_potential</span><span class="p">}</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lepsilon</span><span class="p">:</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;piezo_tensor&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">piezo_tensor</span><span class="p">,</span>
                      <span class="s2">&quot;dielectric_tensor&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_tensor</span><span class="p">,</span>
                      <span class="s2">&quot;born&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">born</span><span class="p">})</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dfpt</span><span class="p">:</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;internal_strain_tensor&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">internal_strain_tensor</span><span class="p">})</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dfpt</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">lepsilon</span><span class="p">:</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;piezo_ionic_tensor&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">piezo_ionic_tensor</span><span class="p">,</span>
                      <span class="s2">&quot;dielectric_ionic_tensor&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">dielectric_ionic_tensor</span><span class="p">})</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lcalcpol</span><span class="p">:</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s1">&#39;p_elec&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">p_elec</span><span class="p">,</span>
                      <span class="s1">&#39;p_ion&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">p_ion</span><span class="p">})</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">noncollinear</span><span class="p">:</span>
                <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s1">&#39;p_sp1&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">p_sp1</span><span class="p">,</span>
                          <span class="s1">&#39;p_sp2&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">p_sp2</span><span class="p">})</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s1">&#39;zval_dict&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">zval_dict</span><span class="p">})</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">nmr_cs</span><span class="p">:</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;nmr_cs&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;valence and core&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;chemical_shielding&quot;</span><span class="p">][</span><span class="s2">&quot;valence_and_core&quot;</span><span class="p">],</span>
                                 <span class="s2">&quot;valence_only&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;chemical_shielding&quot;</span><span class="p">][</span><span class="s2">&quot;valence_only&quot;</span><span class="p">],</span>
                                 <span class="s2">&quot;g0&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;cs_g0_contribution&quot;</span><span class="p">],</span>
                                 <span class="s2">&quot;core&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;cs_core_contribution&quot;</span><span class="p">],</span>
                                 <span class="s2">&quot;raw&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;unsym_cs_tensor&quot;</span><span class="p">]}})</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">nmr_efg</span><span class="p">:</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;nmr_efg&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;raw&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;unsym_efg_tensor&quot;</span><span class="p">],</span>
                                  <span class="s2">&quot;parameters&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;efg&quot;</span><span class="p">]}})</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_onsite_density_matrices</span><span class="p">:</span>
            <span class="c1"># cast Spin to str for consistency with electronic_structure</span>
            <span class="c1"># TODO: improve handling of Enum (de)serialization in monty</span>
            <span class="n">onsite_density_matrices</span> <span class="o">=</span> <span class="p">[{</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">):</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
                                       <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;onsite_density_matrices&quot;</span><span class="p">]]</span>
            <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;onsite_density_matrices&quot;</span><span class="p">:</span> <span class="n">onsite_density_matrices</span><span class="p">})</span>

        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="Outcar.read_fermi_contact_shift"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Outcar.read_fermi_contact_shift">[docs]</a>    <span class="k">def</span> <span class="nf">read_fermi_contact_shift</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        output example:</span>
<span class="sd">        Fermi contact (isotropic) hyperfine coupling parameter (MHz)</span>
<span class="sd">        -------------------------------------------------------------</span>
<span class="sd">        ion      A_pw      A_1PS     A_1AE     A_1c      A_tot</span>
<span class="sd">        -------------------------------------------------------------</span>
<span class="sd">         1      -0.002    -0.002    -0.051     0.000    -0.052</span>
<span class="sd">         2      -0.002    -0.002    -0.051     0.000    -0.052</span>
<span class="sd">         3       0.056     0.056     0.321    -0.048     0.321</span>
<span class="sd">        -------------------------------------------------------------</span>
<span class="sd">        , which corresponds to</span>
<span class="sd">        [[-0.002, -0.002, -0.051, 0.0, -0.052],</span>
<span class="sd">         [-0.002, -0.002, -0.051, 0.0, -0.052],</span>
<span class="sd">         [0.056, 0.056, 0.321, -0.048, 0.321]] from &#39;fch&#39; data</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># Fermi contact (isotropic) hyperfine coupling parameter (MHz)</span>
        <span class="n">header_pattern1</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s*Fermi contact \(isotropic\) hyperfine coupling parameter \(MHz\)\s+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*\-+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*ion\s+A_pw\s+A_1PS\s+A_1AE\s+A_1c\s+A_tot\s+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*\-+&quot;</span>
        <span class="n">row_pattern1</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;(?:\d+)\s+&#39;</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;\s+&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s1">&#39;([-]?\d+\.\d+)&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">5</span><span class="p">)</span>
        <span class="n">footer_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\-+&quot;</span>
        <span class="n">fch_table</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern1</span><span class="p">,</span> <span class="n">row_pattern1</span><span class="p">,</span>
                                            <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span>
                                            <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Dipolar hyperfine coupling parameters (MHz)</span>
        <span class="n">header_pattern2</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s*Dipolar hyperfine coupling parameters \(MHz\)\s+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*\-+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*ion\s+A_xx\s+A_yy\s+A_zz\s+A_xy\s+A_xz\s+A_yz\s+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*\-+&quot;</span>
        <span class="n">row_pattern2</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;(?:\d+)\s+&#39;</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;\s+&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s1">&#39;([-]?\d+\.\d+)&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">6</span><span class="p">)</span>
        <span class="n">dh_table</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern2</span><span class="p">,</span> <span class="n">row_pattern2</span><span class="p">,</span>
                                           <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span>
                                           <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Total hyperfine coupling parameters after diagonalization (MHz)</span>
        <span class="n">header_pattern3</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;\s*Total hyperfine coupling parameters after diagonalization \(MHz\)\s+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*\(convention: \|A_zz\| &gt; \|A_xx\| &gt; \|A_yy\|\)\s+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*\-+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*ion\s+A_xx\s+A_yy\s+A_zz\s+asymmetry \(A_yy - A_xx\)/ A_zz\s+&quot;</span> \
                          <span class="sa">r</span><span class="s2">&quot;\s*\-+&quot;</span>
        <span class="n">row_pattern3</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">&#39;(?:\d+)\s+&#39;</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">&#39;\s+&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">r</span><span class="s1">&#39;([-]?\d+\.\d+)&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">4</span><span class="p">)</span>
        <span class="n">th_table</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">read_table_pattern</span><span class="p">(</span><span class="n">header_pattern3</span><span class="p">,</span> <span class="n">row_pattern3</span><span class="p">,</span>
                                           <span class="n">footer_pattern</span><span class="p">,</span> <span class="n">postprocess</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span>
                                           <span class="n">last_one_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="n">fc_shift_table</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;fch&#39;</span><span class="p">:</span> <span class="n">fch_table</span><span class="p">,</span> <span class="s1">&#39;dh&#39;</span><span class="p">:</span> <span class="n">dh_table</span><span class="p">,</span> <span class="s1">&#39;th&#39;</span><span class="p">:</span> <span class="n">th_table</span><span class="p">}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;fermi_contact_shift&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">fc_shift_table</span></div></div>


<div class="viewcode-block" id="VolumetricData"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData">[docs]</a><span class="k">class</span> <span class="nc">VolumetricData</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Simple volumetric object for reading LOCPOT and CHGCAR type files.</span>

<span class="sd">    .. attribute:: structure</span>

<span class="sd">        Structure associated with the Volumetric Data object</span>

<span class="sd">    ..attribute:: is_spin_polarized</span>

<span class="sd">        True if run is spin polarized</span>

<span class="sd">    ..attribute:: dim</span>

<span class="sd">        Tuple of dimensions of volumetric grid in each direction (nx, ny, nz).</span>

<span class="sd">    ..attribute:: data</span>

<span class="sd">        Actual data as a dict of {string: np.array}. The string are &quot;total&quot;</span>
<span class="sd">        and &quot;diff&quot;, in accordance to the output format of vasp LOCPOT and</span>
<span class="sd">        CHGCAR files where the total spin density is written first, followed</span>
<span class="sd">        by the difference spin density.</span>

<span class="sd">    .. attribute:: ngridpts</span>

<span class="sd">        Total number of grid points in volumetric data.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">distance_matrix</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">data_aug</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Typically, this constructor is not used directly and the static</span>
<span class="sd">        from_file constructor is used. This constructor is designed to allow</span>
<span class="sd">        summation and other operations between VolumetricData objects.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: Structure associated with the volumetric data</span>
<span class="sd">            data: Actual volumetric data.</span>
<span class="sd">            data_aug: Any extra information associated with volumetric data</span>
<span class="sd">                (typically augmentation charges)</span>
<span class="sd">            distance_matrix: A pre-computed distance matrix if available.</span>
<span class="sd">                Useful so pass distance_matrices between sums,</span>
<span class="sd">                shortcircuiting an otherwise expensive operation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">2</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_soc</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">4</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dim</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_aug</span> <span class="o">=</span> <span class="n">data_aug</span> <span class="k">if</span> <span class="n">data_aug</span> <span class="k">else</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ngridpts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="c1"># lazy init the spin data since this is not always needed.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_spin_data</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span> <span class="o">=</span> <span class="p">{}</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">distance_matrix</span> <span class="k">else</span> <span class="n">distance_matrix</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">xpoints</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="n">num</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ypoints</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="n">num</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">zpoints</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="n">num</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">dim</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">interpolator</span> <span class="o">=</span> <span class="n">RegularGridInterpolator</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">xpoints</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ypoints</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">zpoints</span><span class="p">),</span> 
                                                    <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">],</span> <span class="n">bounds_error</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">spin_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        The data decomposed into actual spin data as {spin: data}.</span>
<span class="sd">        Essentially, this provides the actual Spin.up and Spin.down data</span>
<span class="sd">        instead of the total and diff.  Note that by definition, a</span>
<span class="sd">        non-spin-polarized run would have Spin.up data == Spin.down data.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_spin_data</span><span class="p">:</span>
            <span class="n">spin_data</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
            <span class="n">spin_data</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">]</span> <span class="o">+</span>
                                        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;diff&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
            <span class="n">spin_data</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">]</span> <span class="o">-</span>
                                          <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;diff&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_spin_data</span> <span class="o">=</span> <span class="n">spin_data</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_spin_data</span>

<div class="viewcode-block" id="VolumetricData.get_axis_grid"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.get_axis_grid">[docs]</a>    <span class="k">def</span> <span class="nf">get_axis_grid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ind</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the grid for a particular axis.</span>

<span class="sd">        Args:</span>
<span class="sd">            ind (int): Axis index.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ng</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span>
        <span class="n">num_pts</span> <span class="o">=</span> <span class="n">ng</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span>
        <span class="n">lengths</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">abc</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">i</span> <span class="o">/</span> <span class="n">num_pts</span> <span class="o">*</span> <span class="n">lengths</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">num_pts</span><span class="p">)]</span></div>

    <span class="k">def</span> <span class="fm">__add__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">linear_add</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__sub__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">linear_add</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">)</span>

<div class="viewcode-block" id="VolumetricData.copy"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Copy of Volumetric object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">VolumetricData</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span>
            <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
            <span class="n">distance_matrix</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span><span class="p">,</span>
            <span class="n">data_aug</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data_aug</span>
        <span class="p">)</span></div>

<div class="viewcode-block" id="VolumetricData.linear_add"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.linear_add">[docs]</a>    <span class="k">def</span> <span class="nf">linear_add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">,</span> <span class="n">scale_factor</span><span class="o">=</span><span class="mf">1.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method to do a linear sum of volumetric objects. Used by + and -</span>
<span class="sd">        operators as well. Returns a VolumetricData object containing the</span>
<span class="sd">        linear sum.</span>

<span class="sd">        Args:</span>
<span class="sd">            other (VolumetricData): Another VolumetricData object</span>
<span class="sd">            scale_factor (float): Factor to scale the other data by.</span>

<span class="sd">        Returns:</span>
<span class="sd">            VolumetricData corresponding to self + scale_factor * other.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">structure</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Structures are different. Make sure you know what &quot;</span>
                          <span class="s2">&quot;you are doing...&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Data have different keys! Maybe one is spin-&quot;</span>
                             <span class="s2">&quot;polarized and the other is not?&quot;</span><span class="p">)</span>

        <span class="c1"># To add checks</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">+</span> <span class="n">scale_factor</span> <span class="o">*</span> <span class="n">other</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">VolumetricData</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span><span class="p">)</span></div>

<div class="viewcode-block" id="VolumetricData.parse_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.parse_file">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">parse_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenience method to parse a generic volumetric data file in the vasp</span>
<span class="sd">        like format. Used by subclasses for parsing file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Path of file to parse</span>

<span class="sd">        Returns:</span>
<span class="sd">            (poscar, data)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">poscar_read</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">poscar_string</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">dataset</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">all_dataset</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># for holding any strings in input that are not Poscar</span>
        <span class="c1"># or VolumetricData (typically augmentation charges)</span>
        <span class="n">all_dataset_aug</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">dim</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">dimline</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">read_dataset</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">ngrid_pts</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">data_count</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">poscar</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">original_line</span> <span class="o">=</span> <span class="n">line</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">read_dataset</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">tok</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">():</span>
                        <span class="k">if</span> <span class="n">data_count</span> <span class="o">&lt;</span> <span class="n">ngrid_pts</span><span class="p">:</span>
                            <span class="c1"># This complicated procedure is necessary because</span>
                            <span class="c1"># vasp outputs x as the fastest index, followed by y</span>
                            <span class="c1"># then z.</span>
                            <span class="n">no_x</span> <span class="o">=</span> <span class="n">data_count</span> <span class="o">//</span> <span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                            <span class="n">dataset</span><span class="p">[</span>
                                <span class="n">data_count</span> <span class="o">%</span> <span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                <span class="n">no_x</span> <span class="o">%</span> <span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                                <span class="n">no_x</span> <span class="o">//</span> <span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                            <span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">tok</span><span class="p">)</span>
                            <span class="n">data_count</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="k">if</span> <span class="n">data_count</span> <span class="o">&gt;=</span> <span class="n">ngrid_pts</span><span class="p">:</span>
                        <span class="n">read_dataset</span> <span class="o">=</span> <span class="kc">False</span>
                        <span class="n">data_count</span> <span class="o">=</span> <span class="mi">0</span>
                        <span class="n">all_dataset</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dataset</span><span class="p">)</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">poscar_read</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">line</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">poscar_string</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">poscar_string</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">line</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
                        <span class="n">poscar</span> <span class="o">=</span> <span class="n">Poscar</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">poscar_string</span><span class="p">))</span>
                        <span class="n">poscar_read</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">dim</span><span class="p">:</span>
                    <span class="n">dim</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
                    <span class="n">ngrid_pts</span> <span class="o">=</span> <span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
                    <span class="n">dimline</span> <span class="o">=</span> <span class="n">line</span>
                    <span class="n">read_dataset</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="n">dataset</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">dim</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">line</span> <span class="o">==</span> <span class="n">dimline</span><span class="p">:</span>
                    <span class="c1"># when line == dimline, expect volumetric data to follow</span>
                    <span class="c1"># so set read_dataset to True</span>
                    <span class="n">read_dataset</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="n">dataset</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">dim</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="c1"># store any extra lines that were not part of the</span>
                    <span class="c1"># volumetric data so we know which set of data the extra</span>
                    <span class="c1"># lines are associated with</span>
                    <span class="n">key</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">all_dataset</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
                    <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">all_dataset_aug</span><span class="p">:</span>
                        <span class="n">all_dataset_aug</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="n">all_dataset_aug</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">original_line</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">all_dataset</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>

                <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;total&quot;</span><span class="p">:</span> <span class="n">all_dataset</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s2">&quot;diff_x&quot;</span><span class="p">:</span> <span class="n">all_dataset</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                        <span class="s2">&quot;diff_y&quot;</span><span class="p">:</span> <span class="n">all_dataset</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="s2">&quot;diff_z&quot;</span><span class="p">:</span> <span class="n">all_dataset</span><span class="p">[</span><span class="mi">3</span><span class="p">]}</span>
                <span class="n">data_aug</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;total&quot;</span><span class="p">:</span> <span class="n">all_dataset_aug</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
                            <span class="s2">&quot;diff_x&quot;</span><span class="p">:</span> <span class="n">all_dataset_aug</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
                            <span class="s2">&quot;diff_y&quot;</span><span class="p">:</span> <span class="n">all_dataset_aug</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
                            <span class="s2">&quot;diff_z&quot;</span><span class="p">:</span> <span class="n">all_dataset_aug</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="kc">None</span><span class="p">)}</span>

                <span class="c1"># construct a &quot;diff&quot; dict for scalar-like magnetization density,</span>
                <span class="c1"># referenced to an arbitrary direction (using same method as</span>
                <span class="c1"># pymatgen.electronic_structure.core.Magmom, see</span>
                <span class="c1"># Magmom documentation for justification for this)</span>
                <span class="c1"># TODO: re-examine this, and also similar behavior in</span>
                <span class="c1"># Magmom - @mkhorton</span>
                <span class="c1"># TODO: does CHGCAR change with different SAXIS?</span>
                <span class="n">diff_xyz</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;diff_x&quot;</span><span class="p">],</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;diff_y&quot;</span><span class="p">],</span>
                                     <span class="n">data</span><span class="p">[</span><span class="s2">&quot;diff_z&quot;</span><span class="p">]])</span>
                <span class="n">diff_xyz</span> <span class="o">=</span> <span class="n">diff_xyz</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
                <span class="n">ref_direction</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.01</span><span class="p">,</span> <span class="mf">1.02</span><span class="p">,</span> <span class="mf">1.03</span><span class="p">])</span>
                <span class="n">ref_sign</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">ref_direction</span><span class="p">,</span> <span class="n">diff_xyz</span><span class="p">))</span>
                <span class="n">diff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">diff_xyz</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span> <span class="n">ref_sign</span><span class="p">)</span>
                <span class="n">data</span><span class="p">[</span><span class="s2">&quot;diff&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">diff</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">dim</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">dim</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dim</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>

            <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">all_dataset</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;total&quot;</span><span class="p">:</span> <span class="n">all_dataset</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s2">&quot;diff&quot;</span><span class="p">:</span> <span class="n">all_dataset</span><span class="p">[</span><span class="mi">1</span><span class="p">]}</span>
                <span class="n">data_aug</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;total&quot;</span><span class="p">:</span> <span class="n">all_dataset_aug</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
                            <span class="s2">&quot;diff&quot;</span><span class="p">:</span> <span class="n">all_dataset_aug</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="kc">None</span><span class="p">)}</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;total&quot;</span><span class="p">:</span> <span class="n">all_dataset</span><span class="p">[</span><span class="mi">0</span><span class="p">]}</span>
                <span class="n">data_aug</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;total&quot;</span><span class="p">:</span> <span class="n">all_dataset_aug</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">None</span><span class="p">)}</span>
            <span class="k">return</span> <span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">data_aug</span></div>

<div class="viewcode-block" id="VolumetricData.write_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.write_file">[docs]</a>    <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">file_name</span><span class="p">,</span> <span class="n">vasp4_compatible</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write the VolumetricData object to a vasp compatible file.</span>

<span class="sd">        Args:</span>
<span class="sd">            file_name (str): Path to a file</span>
<span class="sd">            vasp4_compatible (bool): True if the format is vasp4 compatible</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">def</span> <span class="nf">_print_fortran_float</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Fortran codes print floats with a leading zero in scientific</span>
<span class="sd">            notation. When writing CHGCAR files, we adopt this convention</span>
<span class="sd">            to ensure written CHGCAR files are byte-to-byte identical to</span>
<span class="sd">            their input files as far as possible.</span>
<span class="sd">            :param f: float</span>
<span class="sd">            :return: str</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">s</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{:.10E}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">f</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">return</span> <span class="s2">&quot;0.&quot;</span> <span class="o">+</span> <span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">s</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">12</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;E&#39;</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="si">{:+03}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="mi">13</span><span class="p">:])</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="s2">&quot;-.&quot;</span> <span class="o">+</span> <span class="n">s</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">s</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">13</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;E&#39;</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="si">{:+03}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="mi">14</span><span class="p">:])</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>

        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">Poscar</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>

            <span class="c1"># use original name if it&#39;s been set (e.g. from Chgcar)</span>
            <span class="n">comment</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">comment</span><span class="p">)</span>

            <span class="n">lines</span> <span class="o">=</span> <span class="n">comment</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot;   1.00000000000000</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">latt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span>
            <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot; </span><span class="si">%12.6f%12.6f%12.6f</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">latt</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:])</span>
            <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot; </span><span class="si">%12.6f%12.6f%12.6f</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">latt</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:])</span>
            <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot; </span><span class="si">%12.6f%12.6f%12.6f</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">latt</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">vasp4_compatible</span><span class="p">:</span>
                <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">%5s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">s</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">site_symbols</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">%6d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">natoms</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot;Direct</span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">:</span>
                <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">%10.6f%10.6f%10.6f</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">)</span>
            <span class="n">lines</span> <span class="o">+=</span> <span class="s2">&quot; </span><span class="se">\n</span><span class="s2">&quot;</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>
            <span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span>

            <span class="k">def</span> <span class="nf">write_spin</span><span class="p">(</span><span class="n">data_type</span><span class="p">):</span>
                <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;   </span><span class="si">{}</span><span class="s2">   </span><span class="si">{}</span><span class="s2">   </span><span class="si">{}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
                <span class="k">for</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">])),</span>
                                                   <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">])),</span>
                                                   <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]))):</span>
                    <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_print_fortran_float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">data_type</span><span class="p">][</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">k</span><span class="p">]))</span>
                    <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="k">if</span> <span class="n">count</span> <span class="o">%</span> <span class="mi">5</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                        <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">count</span> <span class="o">%</span> <span class="mi">5</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; </span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data_aug</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">data_type</span><span class="p">,</span> <span class="p">[])))</span>

            <span class="n">write_spin</span><span class="p">(</span><span class="s2">&quot;total&quot;</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_soc</span><span class="p">:</span>
                <span class="n">write_spin</span><span class="p">(</span><span class="s2">&quot;diff_x&quot;</span><span class="p">)</span>
                <span class="n">write_spin</span><span class="p">(</span><span class="s2">&quot;diff_y&quot;</span><span class="p">)</span>
                <span class="n">write_spin</span><span class="p">(</span><span class="s2">&quot;diff_z&quot;</span><span class="p">)</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
                <span class="n">write_spin</span><span class="p">(</span><span class="s2">&quot;diff&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="VolumetricData.value_at"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.value_at">[docs]</a>    <span class="k">def</span> <span class="nf">value_at</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a data value from self.data at a given point (x, y, z) in terms </span>
<span class="sd">        of fractional lattice parameters. Will be interpolated using a </span>
<span class="sd">        RegularGridInterpolator on self.data if (x, y, z) is not in the original </span>
<span class="sd">        set of data points.</span>

<span class="sd">        Args:</span>
<span class="sd">            x (float): Fraction of lattice vector a.</span>
<span class="sd">            y (float): Fraction of lattice vector b.</span>
<span class="sd">            z (float): Fraction of lattice vector c.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Value from self.data (potentially interpolated) correspondisng to </span>
<span class="sd">            the point (x, y, z).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">interpolator</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="VolumetricData.linear_slice"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.linear_slice">[docs]</a>    <span class="k">def</span> <span class="nf">linear_slice</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">100</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a linear slice of the volumetric data with n data points from</span>
<span class="sd">        point p1 to point p2, in the form of a list.</span>

<span class="sd">        Args:</span>
<span class="sd">            p1 (list): 3-element list containing fractional coordinates of the first point.</span>
<span class="sd">            p2 (list): 3-element list containing fractional coordinates of the second point.</span>
<span class="sd">            n (int): Number of data points to collect, defaults to 100.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of n data points (mostly interpolated) representing a linear slice of the </span>
<span class="sd">            data from point p1 to point p2.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">assert</span> <span class="nb">type</span><span class="p">(</span><span class="n">p1</span><span class="p">)</span> <span class="ow">in</span> <span class="p">[</span><span class="nb">list</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span> <span class="ow">and</span> <span class="nb">type</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span> <span class="ow">in</span> <span class="p">[</span><span class="nb">list</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">]</span>
        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">p1</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span>
        <span class="n">xpts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">num</span><span class="o">=</span><span class="n">n</span><span class="p">)</span>
        <span class="n">ypts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">num</span><span class="o">=</span><span class="n">n</span><span class="p">)</span>
        <span class="n">zpts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">p2</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">num</span><span class="o">=</span><span class="n">n</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">value_at</span><span class="p">(</span><span class="n">xpts</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">ypts</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">zpts</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">)]</span></div>

<div class="viewcode-block" id="VolumetricData.get_integrated_diff"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.get_integrated_diff">[docs]</a>    <span class="k">def</span> <span class="nf">get_integrated_diff</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ind</span><span class="p">,</span> <span class="n">radius</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get integrated difference of atom index ind up to radius. This can be</span>
<span class="sd">        an extremely computationally intensive process, depending on how many</span>
<span class="sd">        grid points are in the VolumetricData.</span>

<span class="sd">        Args:</span>
<span class="sd">            ind (int): Index of atom.</span>
<span class="sd">            radius (float): Radius of integration.</span>
<span class="sd">            nbins (int): Number of bins. Defaults to 1. This allows one to</span>
<span class="sd">                obtain the charge integration up to a list of the cumulative</span>
<span class="sd">                charge integration values for radii for [radius/nbins,</span>
<span class="sd">                2 * radius/nbins, ....].</span>

<span class="sd">        Returns:</span>
<span class="sd">            Differential integrated charge as a np array of [[radius, value],</span>
<span class="sd">            ...]. Format is for ease of plotting. E.g., plt.plot(data[:,0],</span>
<span class="sd">            data[:,1])</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># For non-spin-polarized runs, this is zero by definition.</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
            <span class="n">radii</span> <span class="o">=</span> <span class="p">[</span><span class="n">radius</span> <span class="o">/</span> <span class="n">nbins</span> <span class="o">*</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbins</span><span class="p">)]</span>
            <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nbins</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
            <span class="n">data</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">radii</span>
            <span class="k">return</span> <span class="n">data</span>

        <span class="n">struct</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span>
        <span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span>
        <span class="k">if</span> <span class="n">ind</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span> <span class="ow">or</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span><span class="p">[</span><span class="n">ind</span><span class="p">][</span><span class="s2">&quot;max_radius&quot;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">radius</span><span class="p">:</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">a</span><span class="p">]):</span>
                <span class="n">coords</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">x</span> <span class="o">/</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">y</span> <span class="o">/</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">z</span> <span class="o">/</span> <span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
            <span class="n">sites_dist</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">get_points_in_sphere</span><span class="p">(</span>
                <span class="n">coords</span><span class="p">,</span> <span class="n">struct</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="n">radius</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;max_radius&quot;</span><span class="p">:</span> <span class="n">radius</span><span class="p">,</span>
                                          <span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">sites_dist</span><span class="p">)}</span>

        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span><span class="p">[</span><span class="n">ind</span><span class="p">][</span><span class="s2">&quot;data&quot;</span><span class="p">]</span>

        <span class="c1"># Use boolean indexing to find all charges within the desired distance.</span>
        <span class="n">inds</span> <span class="o">=</span> <span class="n">data</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">radius</span>
        <span class="n">dists</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">inds</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="n">data_inds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">rint</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mod</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">inds</span><span class="p">,</span> <span class="mi">0</span><span class="p">]),</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span>
                            <span class="n">np</span><span class="o">.</span><span class="n">tile</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">dists</span><span class="p">),</span> <span class="mi">1</span><span class="p">)))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
        <span class="n">vals</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;diff&quot;</span><span class="p">][</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="ow">in</span> <span class="n">data_inds</span><span class="p">]</span>

        <span class="n">hist</span><span class="p">,</span> <span class="n">edges</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">histogram</span><span class="p">(</span><span class="n">dists</span><span class="p">,</span> <span class="n">bins</span><span class="o">=</span><span class="n">nbins</span><span class="p">,</span>
                                   <span class="nb">range</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">radius</span><span class="p">],</span>
                                   <span class="n">weights</span><span class="o">=</span><span class="n">vals</span><span class="p">)</span>
        <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nbins</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
        <span class="n">data</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">edges</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
        <span class="n">data</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">sum</span><span class="p">(</span><span class="n">hist</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">ngridpts</span>
                      <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nbins</span><span class="p">)]</span>
        <span class="k">return</span> <span class="n">data</span></div>

<div class="viewcode-block" id="VolumetricData.get_average_along_axis"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.get_average_along_axis">[docs]</a>    <span class="k">def</span> <span class="nf">get_average_along_axis</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ind</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the averaged total of the volumetric data a certain axis direction.</span>
<span class="sd">        For example, useful for visualizing Hartree Potentials from a LOCPOT</span>
<span class="sd">        file.</span>

<span class="sd">        Args:</span>
<span class="sd">            ind (int): Index of axis.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Average total along axis</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">m</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">]</span>
        <span class="n">ng</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span>
        <span class="k">if</span> <span class="n">ind</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">total</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="mi">1</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">ind</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">total</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span> <span class="mi">1</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">total</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">total</span> <span class="o">/</span> <span class="n">ng</span><span class="p">[(</span><span class="n">ind</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">%</span> <span class="mi">3</span><span class="p">]</span> <span class="o">/</span> <span class="n">ng</span><span class="p">[(</span><span class="n">ind</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span> <span class="o">%</span> <span class="mi">3</span><span class="p">]</span></div>

<div class="viewcode-block" id="VolumetricData.to_hdf5"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.to_hdf5">[docs]</a>    <span class="k">def</span> <span class="nf">to_hdf5</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes the VolumetricData to a HDF5 format, which is a highly optimized</span>
<span class="sd">        format for reading storing large data. The mapping of the VolumetricData</span>
<span class="sd">        to this file format is as follows:</span>

<span class="sd">        VolumetricData.data -&gt; f[&quot;vdata&quot;]</span>
<span class="sd">        VolumetricData.structure -&gt;</span>
<span class="sd">            f[&quot;Z&quot;]: Sequence of atomic numbers</span>
<span class="sd">            f[&quot;fcoords&quot;]: Fractional coords</span>
<span class="sd">            f[&quot;lattice&quot;]: Lattice in the pymatgen.core.lattice.Lattice matrix</span>
<span class="sd">                format</span>
<span class="sd">            f.attrs[&quot;structure_json&quot;]: String of json representation</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename to output to.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">h5py</span>
        <span class="k">with</span> <span class="n">h5py</span><span class="o">.</span><span class="n">File</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">ds</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">create_dataset</span><span class="p">(</span><span class="s2">&quot;lattice&quot;</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float&#39;</span><span class="p">)</span>
            <span class="n">ds</span><span class="p">[</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span>
            <span class="n">ds</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">create_dataset</span><span class="p">(</span><span class="s2">&quot;Z&quot;</span><span class="p">,</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">species</span><span class="p">),),</span>
                                  <span class="n">dtype</span><span class="o">=</span><span class="s2">&quot;i&quot;</span><span class="p">)</span>
            <span class="n">ds</span><span class="p">[</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">sp</span><span class="o">.</span><span class="n">Z</span> <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">species</span><span class="p">])</span>
            <span class="n">ds</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">create_dataset</span><span class="p">(</span><span class="s2">&quot;fcoords&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">frac_coords</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span>
                                  <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float&#39;</span><span class="p">)</span>
            <span class="n">ds</span><span class="p">[</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">frac_coords</span>
            <span class="n">dt</span> <span class="o">=</span> <span class="n">h5py</span><span class="o">.</span><span class="n">special_dtype</span><span class="p">(</span><span class="n">vlen</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
            <span class="n">ds</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">create_dataset</span><span class="p">(</span><span class="s2">&quot;species&quot;</span><span class="p">,</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">species</span><span class="p">),),</span>
                                  <span class="n">dtype</span><span class="o">=</span><span class="n">dt</span><span class="p">)</span>
            <span class="n">ds</span><span class="p">[</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">sp</span><span class="p">)</span> <span class="k">for</span> <span class="n">sp</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">species</span><span class="p">]</span>
            <span class="n">grp</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">create_group</span><span class="p">(</span><span class="s2">&quot;vdata&quot;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">ds</span> <span class="o">=</span> <span class="n">grp</span><span class="o">.</span><span class="n">create_dataset</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float&#39;</span><span class="p">)</span>
                <span class="n">ds</span><span class="p">[</span><span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
            <span class="n">f</span><span class="o">.</span><span class="n">attrs</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
            <span class="n">f</span><span class="o">.</span><span class="n">attrs</span><span class="p">[</span><span class="s2">&quot;structure_json&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">())</span></div>

<div class="viewcode-block" id="VolumetricData.from_hdf5"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VolumetricData.from_hdf5">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_hdf5</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads VolumetricData from HDF5 file.</span>

<span class="sd">        :param filename: Filename</span>
<span class="sd">        :return: VolumetricData</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">h5py</span>
        <span class="k">with</span> <span class="n">h5py</span><span class="o">.</span><span class="n">File</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">f</span><span class="p">[</span><span class="s2">&quot;vdata&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="n">data_aug</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">if</span> <span class="s1">&#39;vdata_aug&#39;</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">data_aug</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">f</span><span class="p">[</span><span class="s2">&quot;vdata_aug&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">attrs</span><span class="p">[</span><span class="s2">&quot;structure_json&quot;</span><span class="p">]))</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">data_aug</span><span class="o">=</span><span class="n">data_aug</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Locpot"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Locpot">[docs]</a><span class="k">class</span> <span class="nc">Locpot</span><span class="p">(</span><span class="n">VolumetricData</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Simple object for reading a LOCPOT file.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            poscar (Poscar): Poscar object containing structure.</span>
<span class="sd">            data: Actual data.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">poscar</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">poscar</span><span class="o">.</span><span class="n">comment</span>

<div class="viewcode-block" id="Locpot.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Locpot.from_file">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads a LOCPOT file.</span>

<span class="sd">        :param filename: Filename</span>
<span class="sd">        :return: Locpot</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">data_aug</span><span class="p">)</span> <span class="o">=</span> <span class="n">VolumetricData</span><span class="o">.</span><span class="n">parse_file</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Chgcar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Chgcar">[docs]</a><span class="k">class</span> <span class="nc">Chgcar</span><span class="p">(</span><span class="n">VolumetricData</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Simple object for reading a CHGCAR file.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">data_aug</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            poscar (Poscar or Structure): Object containing structure.</span>
<span class="sd">            data: Actual data.</span>
<span class="sd">            data_aug: Augmentation charge data</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># allow for poscar or structure files to be passed</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">Poscar</span><span class="p">):</span>
            <span class="n">tmp_struct</span> <span class="o">=</span> <span class="n">poscar</span><span class="o">.</span><span class="n">structure</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">poscar</span> <span class="o">=</span> <span class="n">poscar</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">poscar</span><span class="o">.</span><span class="n">comment</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">Structure</span><span class="p">):</span>
            <span class="n">tmp_struct</span> <span class="o">=</span> <span class="n">poscar</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">poscar</span> <span class="o">=</span> <span class="n">Poscar</span><span class="p">(</span><span class="n">poscar</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">tmp_struct</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">data_aug</span><span class="o">=</span><span class="n">data_aug</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span> <span class="o">=</span> <span class="p">{}</span>

<div class="viewcode-block" id="Chgcar.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Chgcar.from_file">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads a CHGCAR file.</span>

<span class="sd">        :param filename: Filename</span>
<span class="sd">        :return: Chgcar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">data_aug</span><span class="p">)</span> <span class="o">=</span> <span class="n">VolumetricData</span><span class="o">.</span><span class="n">parse_file</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">Chgcar</span><span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">data_aug</span><span class="o">=</span><span class="n">data_aug</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">net_magnetization</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: Net magnetization from Chgcar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_spin_polarized</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;diff&#39;</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span></div>


<div class="viewcode-block" id="Elfcar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Elfcar">[docs]</a><span class="k">class</span> <span class="nc">Elfcar</span><span class="p">(</span><span class="n">VolumetricData</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Read an ELFCAR file which contains the Electron Localization Function (ELF)</span>
<span class="sd">    as calculated by VASP.</span>

<span class="sd">    For ELF, &quot;total&quot; key refers to Spin.up, and &quot;diff&quot; refers to Spin.down.</span>

<span class="sd">    This also contains information on the kinetic energy density.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            poscar (Poscar or Structure): Object containing structure.</span>
<span class="sd">            data: Actual data.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># allow for poscar or structure files to be passed</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">Poscar</span><span class="p">):</span>
            <span class="n">tmp_struct</span> <span class="o">=</span> <span class="n">poscar</span><span class="o">.</span><span class="n">structure</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">poscar</span> <span class="o">=</span> <span class="n">poscar</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">Structure</span><span class="p">):</span>
            <span class="n">tmp_struct</span> <span class="o">=</span> <span class="n">poscar</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">poscar</span> <span class="o">=</span> <span class="n">Poscar</span><span class="p">(</span><span class="n">poscar</span><span class="p">)</span>

        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">tmp_struct</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
        <span class="c1"># TODO: modify VolumetricData so that the correct keys can be used.</span>
        <span class="c1"># for ELF, instead of &quot;total&quot; and &quot;diff&quot; keys we have</span>
        <span class="c1"># &quot;Spin.up&quot; and &quot;Spin.down&quot; keys</span>
        <span class="c1"># I believe this is correct, but there&#39;s not much documentation -mkhorton</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>

<div class="viewcode-block" id="Elfcar.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Elfcar.from_file">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads a ELFCAR file.</span>

<span class="sd">        :param filename: Filename</span>
<span class="sd">        :return: Elfcar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">data_aug</span><span class="p">)</span> <span class="o">=</span> <span class="n">VolumetricData</span><span class="o">.</span><span class="n">parse_file</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></div>

<div class="viewcode-block" id="Elfcar.get_alpha"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Elfcar.get_alpha">[docs]</a>    <span class="k">def</span> <span class="nf">get_alpha</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the parameter alpha where ELF = 1/(1+alpha^2).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">alpha_data</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">alpha</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="n">v</span>
            <span class="n">alpha</span> <span class="o">=</span> <span class="n">alpha</span> <span class="o">-</span> <span class="mi">1</span>
            <span class="n">alpha</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span>
            <span class="n">alpha_data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">alpha</span>
        <span class="k">return</span> <span class="n">VolumetricData</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span> <span class="n">alpha_data</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Procar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Procar">[docs]</a><span class="k">class</span> <span class="nc">Procar</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for reading a PROCAR file.</span>


<span class="sd">    .. attribute:: data</span>

<span class="sd">        The PROCAR data of the form below. It should VASP uses 1-based indexing,</span>
<span class="sd">        but all indices are converted to 0-based here.::</span>

<span class="sd">            {</span>
<span class="sd">                spin: nd.array accessed with (k-point index, band index,</span>
<span class="sd">                                              ion index, orbital index)</span>
<span class="sd">            }</span>

<span class="sd">    .. attribute:: weights</span>

<span class="sd">        The weights associated with each k-point as an nd.array of lenght</span>
<span class="sd">        nkpoints.</span>

<span class="sd">    ..attribute:: phase_factors</span>

<span class="sd">        Phase factors, where present (e.g. LORBIT = 12). A dict of the form:</span>
<span class="sd">        {</span>
<span class="sd">            spin: complex nd.array accessed with (k-point index, band index,</span>
<span class="sd">                                                  ion index, orbital index)</span>
<span class="sd">        }</span>

<span class="sd">    ..attribute:: nbands</span>

<span class="sd">        Number of bands</span>

<span class="sd">    ..attribute:: nkpoints</span>

<span class="sd">        Number of k-points</span>

<span class="sd">    ..attribute:: nions</span>

<span class="sd">        Number of ions</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filename: Name of file containing PROCAR.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">headers</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">preambleexpr</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span>
                <span class="sa">r</span><span class="s2">&quot;# of k-points:\s*(\d+)\s+# of bands:\s*(\d+)\s+# of &quot;</span>
                <span class="sa">r</span><span class="s2">&quot;ions:\s*(\d+)&quot;</span><span class="p">)</span>
            <span class="n">kpointexpr</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^k-point\s+(\d+).*weight = ([0-9\.]+)&quot;</span><span class="p">)</span>
            <span class="n">bandexpr</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^band\s+(\d+)&quot;</span><span class="p">)</span>
            <span class="n">ionexpr</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^ion.*&quot;</span><span class="p">)</span>
            <span class="n">expr</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^([0-9]+)\s+&quot;</span><span class="p">)</span>
            <span class="n">current_kpoint</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">current_band</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">done</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span>
            <span class="n">weights</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">l</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">bandexpr</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">bandexpr</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
                    <span class="n">current_band</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> <span class="o">-</span> <span class="mi">1</span>
                    <span class="n">done</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="k">elif</span> <span class="n">kpointexpr</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">kpointexpr</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
                    <span class="n">current_kpoint</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> <span class="o">-</span> <span class="mi">1</span>
                    <span class="n">weights</span><span class="p">[</span><span class="n">current_kpoint</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">current_kpoint</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="n">spin</span> <span class="o">=</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span> <span class="k">if</span> <span class="n">spin</span> <span class="o">==</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="k">else</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span>
                    <span class="n">done</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="k">elif</span> <span class="n">headers</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">ionexpr</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
                    <span class="n">headers</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">headers</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
                    <span class="n">headers</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

                    <span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
                        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nkpoints</span><span class="p">,</span> <span class="n">nbands</span><span class="p">,</span> <span class="n">nions</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">headers</span><span class="p">)))</span>

                    <span class="n">data</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>

                    <span class="k">def</span> <span class="nf">f2</span><span class="p">():</span>
                        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">full</span><span class="p">((</span><span class="n">nkpoints</span><span class="p">,</span> <span class="n">nbands</span><span class="p">,</span> <span class="n">nions</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">headers</span><span class="p">)),</span>
                                       <span class="n">np</span><span class="o">.</span><span class="n">NaN</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex128</span><span class="p">)</span>

                    <span class="n">phase_factors</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="n">f2</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">expr</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
                    <span class="n">toks</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">index</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">toks</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span> <span class="o">-</span> <span class="mi">1</span>
                    <span class="n">num_data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">[:</span><span class="nb">len</span><span class="p">(</span><span class="n">headers</span><span class="p">)]])</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">done</span><span class="p">:</span>
                        <span class="n">data</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">current_kpoint</span><span class="p">,</span> <span class="n">current_band</span><span class="p">,</span> <span class="n">index</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">num_data</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">toks</span><span class="p">)</span> <span class="o">&gt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">headers</span><span class="p">):</span>
                            <span class="c1"># new format of PROCAR (vasp 5.4.4)</span>
                            <span class="n">num_data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="nb">float</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
                                                 <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">toks</span><span class="p">[:</span><span class="mi">2</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">headers</span><span class="p">)]])</span>
                            <span class="k">for</span> <span class="n">orb</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">headers</span><span class="p">)):</span>
                                <span class="n">phase_factors</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">current_kpoint</span><span class="p">,</span> <span class="n">current_band</span><span class="p">,</span>
                                                    <span class="n">index</span><span class="p">,</span> <span class="n">orb</span><span class="p">]</span> <span class="o">=</span> <span class="nb">complex</span><span class="p">(</span><span class="n">num_data</span><span class="p">[</span><span class="mi">2</span> <span class="o">*</span> <span class="n">orb</span><span class="p">],</span> <span class="n">num_data</span><span class="p">[</span><span class="mi">2</span> <span class="o">*</span> <span class="n">orb</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="c1"># old format of PROCAR (vasp 5.4.1 and before)</span>
                            <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">phase_factors</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">current_kpoint</span><span class="p">,</span> <span class="n">current_band</span><span class="p">,</span> <span class="n">index</span><span class="p">,</span> <span class="mi">0</span><span class="p">]):</span>
                                <span class="n">phase_factors</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">current_kpoint</span><span class="p">,</span> <span class="n">current_band</span><span class="p">,</span> <span class="n">index</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">num_data</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="n">phase_factors</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">current_kpoint</span><span class="p">,</span> <span class="n">current_band</span><span class="p">,</span> <span class="n">index</span><span class="p">,</span> <span class="p">:]</span> <span class="o">+=</span> <span class="mi">1</span><span class="n">j</span> <span class="o">*</span> <span class="n">num_data</span>
                <span class="k">elif</span> <span class="n">l</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;tot&quot;</span><span class="p">):</span>
                    <span class="n">done</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">elif</span> <span class="n">preambleexpr</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">l</span><span class="p">):</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">preambleexpr</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
                    <span class="n">nkpoints</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
                    <span class="n">nbands</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
                    <span class="n">nions</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
                    <span class="n">weights</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">nkpoints</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">nkpoints</span> <span class="o">=</span> <span class="n">nkpoints</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nbands</span> <span class="o">=</span> <span class="n">nbands</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nions</span> <span class="o">=</span> <span class="n">nions</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">weights</span> <span class="o">=</span> <span class="n">weights</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">orbitals</span> <span class="o">=</span> <span class="n">headers</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">phase_factors</span> <span class="o">=</span> <span class="n">phase_factors</span>

<div class="viewcode-block" id="Procar.get_projection_on_elements"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Procar.get_projection_on_elements">[docs]</a>    <span class="k">def</span> <span class="nf">get_projection_on_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method returning a dictionary of projections on elements.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): Input structure.</span>

<span class="sd">        Returns:</span>
<span class="sd">            a dictionary in the {Spin.up:[k index][b index][{Element:values}]]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">dico</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">dico</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="p">[[</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
                           <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nkpoints</span><span class="p">)]</span>
                          <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nbands</span><span class="p">)]</span>

        <span class="k">for</span> <span class="n">iat</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nions</span><span class="p">):</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">species</span><span class="p">[</span><span class="n">iat</span><span class="p">]</span><span class="o">.</span><span class="n">symbol</span>
            <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nkpoints</span><span class="p">),</span>
                                              <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nbands</span><span class="p">)):</span>
                    <span class="n">dico</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">b</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">iat</span><span class="p">,</span> <span class="p">:])</span>

        <span class="k">return</span> <span class="n">dico</span></div>

<div class="viewcode-block" id="Procar.get_occupation"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Procar.get_occupation">[docs]</a>    <span class="k">def</span> <span class="nf">get_occupation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">atom_index</span><span class="p">,</span> <span class="n">orbital</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the occupation for a particular orbital of a particular atom.</span>

<span class="sd">        Args:</span>
<span class="sd">            atom_num (int): Index of atom in the PROCAR. It should be noted</span>
<span class="sd">                that VASP uses 1-based indexing for atoms, but this is</span>
<span class="sd">                converted to 0-based indexing in this parser to be</span>
<span class="sd">                consistent with representation of structures in pymatgen.</span>
<span class="sd">            orbital (str): An orbital. If it is a single character, e.g., s,</span>
<span class="sd">                p, d or f, the sum of all s-type, p-type, d-type or f-type</span>
<span class="sd">                orbitals occupations are returned respectively. If it is a</span>
<span class="sd">                specific orbital, e.g., px, dxy, etc., only the occupation</span>
<span class="sd">                of that orbital is returned.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Sum occupation of orbital of atom.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">orbital_index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">orbitals</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">orbital</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">d</span><span class="p">[:,</span> <span class="p">:,</span> <span class="n">atom_index</span><span class="p">,</span> <span class="n">orbital_index</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">weights</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">])</span>
                <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span></div></div>


<div class="viewcode-block" id="Oszicar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Oszicar">[docs]</a><span class="k">class</span> <span class="nc">Oszicar</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A basic parser for an OSZICAR output from VASP.  In general, while the</span>
<span class="sd">    OSZICAR is useful for a quick look at the output from a VASP run, we</span>
<span class="sd">    recommend that you use the Vasprun parser instead, which gives far richer</span>
<span class="sd">    information about a run.</span>

<span class="sd">    .. attribute:: electronic_steps</span>

<span class="sd">            All electronic steps as a list of list of dict. e.g.,</span>
<span class="sd">            [[{&quot;rms&quot;: 160.0, &quot;E&quot;: 4507.24605593, &quot;dE&quot;: 4507.2, &quot;N&quot;: 1,</span>
<span class="sd">            &quot;deps&quot;: -17777.0, &quot;ncg&quot;: 16576}, ...], [....]</span>
<span class="sd">            where electronic_steps[index] refers the list of electronic steps</span>
<span class="sd">            in one ionic_step, electronic_steps[index][subindex] refers to a</span>
<span class="sd">            particular electronic step at subindex in ionic step at index. The</span>
<span class="sd">            dict of properties depends on the type of VASP run, but in general,</span>
<span class="sd">            &quot;E&quot;, &quot;dE&quot; and &quot;rms&quot; should be present in almost all runs.</span>

<span class="sd">    .. attribute:: ionic_steps:</span>

<span class="sd">            All ionic_steps as a list of dict, e.g.,</span>
<span class="sd">            [{&quot;dE&quot;: -526.36, &quot;E0&quot;: -526.36024, &quot;mag&quot;: 0.0, &quot;F&quot;: -526.36024},</span>
<span class="sd">            ...]</span>
<span class="sd">            This is the typical output from VASP at the end of each ionic step.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename of file to parse</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">electronic_steps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">ionic_steps</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">ionic_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(\d+)\s+F=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                   <span class="sa">r</span><span class="s2">&quot;E0=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                   <span class="sa">r</span><span class="s2">&quot;d\s*E\s*=\s*([\d\-\.E\+]+)$&quot;</span><span class="p">)</span>
        <span class="n">ionic_mag_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(\d+)\s+F=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                       <span class="sa">r</span><span class="s2">&quot;E0=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                       <span class="sa">r</span><span class="s2">&quot;d\s*E\s*=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                       <span class="sa">r</span><span class="s2">&quot;mag=\s*([\d\-\.E\+]+)&quot;</span><span class="p">)</span>
        <span class="n">ionic_MD_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(\d+)\s+T=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                      <span class="sa">r</span><span class="s2">&quot;E=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                      <span class="sa">r</span><span class="s2">&quot;F=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                      <span class="sa">r</span><span class="s2">&quot;E0=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                      <span class="sa">r</span><span class="s2">&quot;EK=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                      <span class="sa">r</span><span class="s2">&quot;SP=\s*([\d\-\.E\+]+)\s+&quot;</span>
                                      <span class="sa">r</span><span class="s2">&quot;SK=\s*([\d\-\.E\+]+)&quot;</span><span class="p">)</span>
        <span class="n">electronic_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\s*\w+\s*:(.*)&quot;</span><span class="p">)</span>

        <span class="k">def</span> <span class="nf">smart_convert</span><span class="p">(</span><span class="n">header</span><span class="p">,</span> <span class="n">num</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">header</span> <span class="o">==</span> <span class="s2">&quot;N&quot;</span> <span class="ow">or</span> <span class="n">header</span> <span class="o">==</span> <span class="s2">&quot;ncg&quot;</span><span class="p">:</span>
                    <span class="n">v</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
                    <span class="k">return</span> <span class="n">v</span>
                <span class="n">v</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">v</span>
            <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                <span class="k">return</span> <span class="s2">&quot;--&quot;</span>

        <span class="n">header</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fid</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">fid</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">electronic_pattern</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                    <span class="n">toks</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="n">header</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span> <span class="n">smart_convert</span><span class="p">(</span><span class="n">header</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">toks</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">toks</span><span class="p">))}</span>
                    <span class="k">if</span> <span class="n">toks</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;1&quot;</span><span class="p">:</span>
                        <span class="n">electronic_steps</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">data</span><span class="p">])</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">electronic_steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">ionic_pattern</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()):</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">ionic_pattern</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
                    <span class="n">ionic_steps</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;F&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                        <span class="s2">&quot;E0&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">)),</span>
                                        <span class="s2">&quot;dE&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">4</span><span class="p">))})</span>
                <span class="k">elif</span> <span class="n">ionic_mag_pattern</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()):</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">ionic_mag_pattern</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
                    <span class="n">ionic_steps</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;F&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                        <span class="s2">&quot;E0&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">)),</span>
                                        <span class="s2">&quot;dE&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">4</span><span class="p">)),</span>
                                        <span class="s2">&quot;mag&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">5</span><span class="p">))})</span>
                <span class="k">elif</span> <span class="n">ionic_MD_pattern</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()):</span>
                    <span class="n">m</span> <span class="o">=</span> <span class="n">ionic_MD_pattern</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
                    <span class="n">ionic_steps</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;T&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span>
                                        <span class="s2">&quot;E&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">3</span><span class="p">)),</span>
                                        <span class="s2">&quot;F&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">4</span><span class="p">)),</span>
                                        <span class="s2">&quot;E0&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">5</span><span class="p">)),</span>
                                        <span class="s2">&quot;EK&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">6</span><span class="p">)),</span>
                                        <span class="s2">&quot;SP&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">7</span><span class="p">)),</span>
                                        <span class="s2">&quot;SK&quot;</span><span class="p">:</span> <span class="nb">float</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">8</span><span class="p">))})</span>
                <span class="k">elif</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;^\s*N\s+E\s*&quot;</span><span class="p">,</span> <span class="n">line</span><span class="p">):</span>
                    <span class="n">header</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;d eps&quot;</span><span class="p">,</span> <span class="s2">&quot;deps&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">electronic_steps</span> <span class="o">=</span> <span class="n">electronic_steps</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span> <span class="o">=</span> <span class="n">ionic_steps</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">all_energies</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compilation of all energies from all electronic steps and ionic steps</span>
<span class="sd">        as a tuple of list of energies, e.g.,</span>
<span class="sd">        ((4507.24605593, 143.824705755, -512.073149912, ...), ...)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">all_energies</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">electronic_steps</span><span class="p">)):</span>
            <span class="n">energies</span> <span class="o">=</span> <span class="p">[</span><span class="n">step</span><span class="p">[</span><span class="s2">&quot;E&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">electronic_steps</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span>
            <span class="n">energies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="s2">&quot;F&quot;</span><span class="p">])</span>
            <span class="n">all_energies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="n">energies</span><span class="p">))</span>
        <span class="k">return</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">all_energies</span><span class="p">)</span>

    <span class="nd">@property</span>  <span class="c1"># type: ignore</span>
    <span class="nd">@unitized</span><span class="p">(</span><span class="s2">&quot;eV&quot;</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">final_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Final energy from run.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s2">&quot;E0&quot;</span><span class="p">]</span>

<div class="viewcode-block" id="Oszicar.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Oszicar.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :return: MSONable dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;electronic_steps&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">electronic_steps</span><span class="p">,</span>
                <span class="s2">&quot;ionic_steps&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ionic_steps</span><span class="p">}</span></div></div>


<div class="viewcode-block" id="VaspParserError"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.VaspParserError">[docs]</a><span class="k">class</span> <span class="nc">VaspParserError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Exception class for VASP parsing.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">pass</span></div>


<div class="viewcode-block" id="get_band_structure_from_vasp_multiple_branches"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.get_band_structure_from_vasp_multiple_branches">[docs]</a><span class="k">def</span> <span class="nf">get_band_structure_from_vasp_multiple_branches</span><span class="p">(</span><span class="n">dir_name</span><span class="p">,</span> <span class="n">efermi</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                                   <span class="n">projections</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This method is used to get band structure info from a VASP directory. It</span>
<span class="sd">    takes into account that the run can be divided in several branches named</span>
<span class="sd">    &quot;branch_x&quot;. If the run has not been divided in branches the method will</span>
<span class="sd">    turn to parsing vasprun.xml directly.</span>

<span class="sd">    The method returns None is there&quot;s a parsing error</span>

<span class="sd">    Args:</span>
<span class="sd">        dir_name: Directory containing all bandstructure runs.</span>
<span class="sd">        efermi: Efermi for bandstructure.</span>
<span class="sd">        projections: True if you want to get the data on site projections if</span>
<span class="sd">            any. Note that this is sometimes very large</span>

<span class="sd">    Returns:</span>
<span class="sd">        A BandStructure Object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># TODO: Add better error handling!!!</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_name</span><span class="p">,</span> <span class="s2">&quot;branch_0&quot;</span><span class="p">)):</span>
        <span class="c1"># get all branch dir names</span>
        <span class="n">branch_dir_names</span> <span class="o">=</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
                            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{i}</span><span class="s2">/branch_*&quot;</span>
                                               <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">dir_name</span><span class="p">))</span>
                            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">d</span><span class="p">)]</span>

        <span class="c1"># sort by the directory name (e.g, branch_10)</span>
        <span class="n">sorted_branch_dir_names</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">branch_dir_names</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;_&quot;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>

        <span class="c1"># populate branches with Bandstructure instances</span>
        <span class="n">branches</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">dir_name</span> <span class="ow">in</span> <span class="n">sorted_branch_dir_names</span><span class="p">:</span>
            <span class="n">xml_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_name</span><span class="p">,</span> <span class="s2">&quot;vasprun.xml&quot;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">xml_file</span><span class="p">):</span>
                <span class="n">run</span> <span class="o">=</span> <span class="n">Vasprun</span><span class="p">(</span><span class="n">xml_file</span><span class="p">,</span> <span class="n">parse_projected_eigen</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span>
                <span class="n">branches</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">run</span><span class="o">.</span><span class="n">get_band_structure</span><span class="p">(</span><span class="n">efermi</span><span class="o">=</span><span class="n">efermi</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># It might be better to throw an exception</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Skipping </span><span class="si">{}</span><span class="s2">. Unable to find </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dir_name</span><span class="p">,</span> <span class="n">xml_file</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">get_reconstructed_band_structure</span><span class="p">(</span><span class="n">branches</span><span class="p">,</span> <span class="n">efermi</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">xml_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dir_name</span><span class="p">,</span> <span class="s2">&quot;vasprun.xml&quot;</span><span class="p">)</span>
        <span class="c1"># Better handling of Errors</span>
        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">xml_file</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">Vasprun</span><span class="p">(</span><span class="n">xml_file</span><span class="p">,</span> <span class="n">parse_projected_eigen</span><span class="o">=</span><span class="n">projections</span><span class="p">)</span> \
                <span class="o">.</span><span class="n">get_band_structure</span><span class="p">(</span><span class="n">kpoints_filename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">efermi</span><span class="o">=</span><span class="n">efermi</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span></div>


<div class="viewcode-block" id="Xdatcar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Xdatcar">[docs]</a><span class="k">class</span> <span class="nc">Xdatcar</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class representing an XDATCAR file. Only tested with VASP 5.x files.</span>

<span class="sd">    .. attribute:: structures</span>

<span class="sd">        List of structures parsed from XDATCAR.</span>
<span class="sd">    .. attribute:: comment</span>

<span class="sd">        Optional comment string.</span>
<span class="sd">    Authors: Ram Balachandran</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">ionicstep_start</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                 <span class="n">ionicstep_end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Init a Xdatcar.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename of input XDATCAR file.</span>
<span class="sd">            ionicstep_start (int): Starting number of ionic step.</span>
<span class="sd">            ionicstep_end (int): Ending number of ionic step.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">preamble</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">coords_str</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">structures</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">preamble_done</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">ionicstep_start</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;Start ionic step cannot be less than 1&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">ionicstep_end</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span>
                <span class="n">ionicstep_start</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;End ionic step cannot be less than 1&#39;</span><span class="p">)</span>

        <span class="n">ionicstep_cnt</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">l</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">preamble</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">preamble</span> <span class="o">=</span> <span class="p">[</span><span class="n">l</span><span class="p">]</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">preamble_done</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">l</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span> <span class="ow">or</span> <span class="s2">&quot;Direct configuration=&quot;</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>
                        <span class="n">preamble_done</span> <span class="o">=</span> <span class="kc">True</span>
                        <span class="n">tmp_preamble</span> <span class="o">=</span> <span class="p">[</span><span class="n">preamble</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
                        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">preamble</span><span class="p">)):</span>
                            <span class="k">if</span> <span class="n">preamble</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">preamble</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
                                <span class="n">tmp_preamble</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">preamble</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="k">break</span>
                        <span class="n">preamble</span> <span class="o">=</span> <span class="n">tmp_preamble</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">preamble</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">l</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span> <span class="ow">or</span> <span class="s2">&quot;Direct configuration=&quot;</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>
                    <span class="n">p</span> <span class="o">=</span> <span class="n">Poscar</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">preamble</span> <span class="o">+</span>
                                                     <span class="p">[</span><span class="s2">&quot;Direct&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">coords_str</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">ionicstep_end</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="k">if</span> <span class="p">(</span><span class="n">ionicstep_cnt</span> <span class="o">&gt;=</span> <span class="n">ionicstep_start</span><span class="p">):</span>
                            <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">ionicstep_start</span> <span class="o">&lt;=</span> <span class="n">ionicstep_cnt</span> <span class="o">&lt;</span> <span class="n">ionicstep_end</span><span class="p">:</span>
                            <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
                        <span class="k">if</span> <span class="n">ionicstep_cnt</span> <span class="o">&gt;=</span> <span class="n">ionicstep_end</span><span class="p">:</span>
                            <span class="k">break</span>
                    <span class="n">ionicstep_cnt</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="n">coords_str</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">coords_str</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">Poscar</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">preamble</span> <span class="o">+</span>
                                             <span class="p">[</span><span class="s2">&quot;Direct&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">coords_str</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">ionicstep_end</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">ionicstep_cnt</span> <span class="o">&gt;=</span> <span class="n">ionicstep_start</span><span class="p">:</span>
                    <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">ionicstep_start</span> <span class="o">&lt;=</span> <span class="n">ionicstep_cnt</span> <span class="o">&lt;</span> <span class="n">ionicstep_end</span><span class="p">:</span>
                    <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structures</span> <span class="o">=</span> <span class="n">structures</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">comment</span> <span class="o">=</span> <span class="n">comment</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">formula</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">site_symbols</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sequence of symbols associated with the Xdatcar. Similar to 6th line in</span>
<span class="sd">        vasp 5+ Xdatcar.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">syms</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">syms</span><span class="p">)]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">natoms</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sequence of number of sites of each type associated with the Poscar.</span>
<span class="sd">        Similar to 7th line in vasp 5+ Xdatcar.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">syms</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
        <span class="k">return</span> <span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">groupby</span><span class="p">(</span><span class="n">syms</span><span class="p">)]</span>

<div class="viewcode-block" id="Xdatcar.concatenate"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Xdatcar.concatenate">[docs]</a>    <span class="k">def</span> <span class="nf">concatenate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">ionicstep_start</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                    <span class="n">ionicstep_end</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Concatenate structures in file to Xdatcar.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename of XDATCAR file to be concatenated.</span>
<span class="sd">            ionicstep_start (int): Starting number of ionic step.</span>
<span class="sd">            ionicstep_end (int): Ending number of ionic step.</span>
<span class="sd">        TODO(rambalachandran):</span>
<span class="sd">           Requires a check to ensure if the new concatenating file has the</span>
<span class="sd">           same lattice structure and atoms as the Xdatcar class.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">preamble</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">coords_str</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">structures</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span>
        <span class="n">preamble_done</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="n">ionicstep_start</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;Start ionic step cannot be less than 1&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">ionicstep_end</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span>
                <span class="n">ionicstep_start</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;End ionic step cannot be less than 1&#39;</span><span class="p">)</span>
        <span class="n">ionicstep_cnt</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">l</span> <span class="o">=</span> <span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">preamble</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">preamble</span> <span class="o">=</span> <span class="p">[</span><span class="n">l</span><span class="p">]</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">preamble_done</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">l</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span> <span class="ow">or</span> <span class="s2">&quot;Direct configuration=&quot;</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>
                        <span class="n">preamble_done</span> <span class="o">=</span> <span class="kc">True</span>
                        <span class="n">tmp_preamble</span> <span class="o">=</span> <span class="p">[</span><span class="n">preamble</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
                        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">preamble</span><span class="p">)):</span>
                            <span class="k">if</span> <span class="n">preamble</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">preamble</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
                                <span class="n">tmp_preamble</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">preamble</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="k">break</span>
                        <span class="n">preamble</span> <span class="o">=</span> <span class="n">tmp_preamble</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">preamble</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">l</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span> <span class="ow">or</span> <span class="s2">&quot;Direct configuration=&quot;</span> <span class="ow">in</span> <span class="n">l</span><span class="p">:</span>
                    <span class="n">p</span> <span class="o">=</span> <span class="n">Poscar</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">preamble</span> <span class="o">+</span>
                                                     <span class="p">[</span><span class="s2">&quot;Direct&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">coords_str</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">ionicstep_end</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="k">if</span> <span class="p">(</span><span class="n">ionicstep_cnt</span> <span class="o">&gt;=</span> <span class="n">ionicstep_start</span><span class="p">):</span>
                            <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">ionicstep_start</span> <span class="o">&lt;=</span> <span class="n">ionicstep_cnt</span> <span class="o">&lt;</span> <span class="n">ionicstep_end</span><span class="p">:</span>
                            <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
                    <span class="n">ionicstep_cnt</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="n">coords_str</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">coords_str</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
            <span class="n">p</span> <span class="o">=</span> <span class="n">Poscar</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">preamble</span> <span class="o">+</span>
                                             <span class="p">[</span><span class="s2">&quot;Direct&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">coords_str</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">ionicstep_end</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">ionicstep_cnt</span> <span class="o">&gt;=</span> <span class="n">ionicstep_start</span><span class="p">:</span>
                    <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">ionicstep_start</span> <span class="o">&lt;=</span> <span class="n">ionicstep_cnt</span> <span class="o">&lt;</span> <span class="n">ionicstep_end</span><span class="p">:</span>
                    <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structures</span> <span class="o">=</span> <span class="n">structures</span></div>

<div class="viewcode-block" id="Xdatcar.get_string"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Xdatcar.get_string">[docs]</a>    <span class="k">def</span> <span class="nf">get_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ionicstep_start</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                   <span class="n">ionicstep_end</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                   <span class="n">significant_figures</span><span class="o">=</span><span class="mi">8</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write  Xdatcar class to a string.</span>

<span class="sd">        Args:</span>
<span class="sd">            ionicstep_start (int): Starting number of ionic step.</span>
<span class="sd">            ionicstep_end (int): Ending number of ionic step.</span>
<span class="sd">            significant_figures (int): Number of significant figures.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">ionicstep_start</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;Start ionic step cannot be less than 1&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">ionicstep_end</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">ionicstep_end</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;End ionic step cannot be less than 1&#39;</span><span class="p">)</span>
        <span class="n">latt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lattice</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">det</span><span class="p">(</span><span class="n">latt</span><span class="o">.</span><span class="n">matrix</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">latt</span> <span class="o">=</span> <span class="n">Lattice</span><span class="p">(</span><span class="o">-</span><span class="n">latt</span><span class="o">.</span><span class="n">matrix</span><span class="p">)</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">comment</span><span class="p">,</span> <span class="s2">&quot;1.0&quot;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">latt</span><span class="p">)]</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site_symbols</span><span class="p">))</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">natoms</span><span class="p">]))</span>
        <span class="n">format_str</span> <span class="o">=</span> <span class="s2">&quot;{{:.</span><span class="si">{0}</span><span class="s2">f}}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">significant_figures</span><span class="p">)</span>
        <span class="n">ionicstep_cnt</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="n">output_cnt</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">for</span> <span class="n">cnt</span><span class="p">,</span> <span class="n">structure</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">):</span>
            <span class="n">ionicstep_cnt</span> <span class="o">=</span> <span class="n">cnt</span> <span class="o">+</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="n">ionicstep_end</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">ionicstep_cnt</span> <span class="o">&gt;=</span> <span class="n">ionicstep_start</span><span class="p">):</span>
                    <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;Direct configuration=&quot;</span> <span class="o">+</span>
                                 <span class="s1">&#39; &#39;</span> <span class="o">*</span> <span class="p">(</span><span class="mi">7</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">output_cnt</span><span class="p">)))</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">output_cnt</span><span class="p">))</span>
                    <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">site</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">structure</span><span class="p">):</span>
                        <span class="n">coords</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span>
                        <span class="n">line</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">format_str</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>
                        <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                    <span class="n">output_cnt</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">ionicstep_start</span> <span class="o">&lt;=</span> <span class="n">ionicstep_cnt</span> <span class="o">&lt;</span> <span class="n">ionicstep_end</span><span class="p">:</span>
                    <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;Direct configuration=&quot;</span> <span class="o">+</span>
                                 <span class="s1">&#39; &#39;</span> <span class="o">*</span> <span class="p">(</span><span class="mi">7</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">output_cnt</span><span class="p">)))</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">output_cnt</span><span class="p">))</span>
                    <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">site</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">structure</span><span class="p">):</span>
                        <span class="n">coords</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span>
                        <span class="n">line</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">format_str</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">coords</span><span class="p">])</span>
                        <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
                    <span class="n">output_cnt</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span></div>

<div class="viewcode-block" id="Xdatcar.write_file"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Xdatcar.write_file">[docs]</a>    <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write  Xdatcar class into a file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename of output XDATCAR file.</span>
<span class="sd">            The supported kwargs are the same as those for the</span>
<span class="sd">            Xdatcar.get_string method and are passed through directly.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">))</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">()</span></div>


<div class="viewcode-block" id="Dynmat"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Dynmat">[docs]</a><span class="k">class</span> <span class="nc">Dynmat</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for reading a DYNMAT file.</span>

<span class="sd">    .. attribute:: data</span>

<span class="sd">        A nested dict containing the DYNMAT data of the form::</span>
<span class="sd">        [atom &lt;int&gt;][disp &lt;int&gt;][&#39;dispvec&#39;] =</span>
<span class="sd">            displacement vector (part of first line in dynmat block, e.g. &quot;0.01 0 0&quot;)</span>
<span class="sd">        [atom &lt;int&gt;][disp &lt;int&gt;][&#39;dynmat&#39;] =</span>
<span class="sd">                &lt;list&gt; list of dynmat lines for this atom and this displacement</span>

<span class="sd">    Authors: Patrick Huck</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filename: Name of file containing DYNMAT</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">lines</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">clean_lines</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">()))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_nspecs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_natoms</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ndisps</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">lines</span><span class="p">[</span>
                <span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_masses</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">())</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">dict</span><span class="p">)</span>
            <span class="n">atom</span><span class="p">,</span> <span class="n">disp</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">l</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">:]):</span>
                <span class="n">v</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">l</span><span class="o">.</span><span class="n">split</span><span class="p">()))</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_natoms</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
                    <span class="n">atom</span><span class="p">,</span> <span class="n">disp</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">v</span><span class="p">[:</span><span class="mi">2</span><span class="p">])</span>
                    <span class="k">if</span> <span class="n">atom</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">atom</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                    <span class="k">if</span> <span class="n">disp</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">atom</span><span class="p">]:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">atom</span><span class="p">][</span><span class="n">disp</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">atom</span><span class="p">][</span><span class="n">disp</span><span class="p">][</span><span class="s1">&#39;dispvec&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span><span class="p">[</span><span class="mi">2</span><span class="p">:]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">if</span> <span class="s1">&#39;dynmat&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">atom</span><span class="p">][</span><span class="n">disp</span><span class="p">]:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">atom</span><span class="p">][</span><span class="n">disp</span><span class="p">][</span><span class="s1">&#39;dynmat&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">atom</span><span class="p">][</span><span class="n">disp</span><span class="p">][</span><span class="s1">&#39;dynmat&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>

<div class="viewcode-block" id="Dynmat.get_phonon_frequencies"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Dynmat.get_phonon_frequencies">[docs]</a>    <span class="k">def</span> <span class="nf">get_phonon_frequencies</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;calculate phonon frequencies&quot;&quot;&quot;</span>
        <span class="c1"># TODO: the following is most likely not correct or suboptimal</span>
        <span class="c1"># hence for demonstration purposes only</span>
        <span class="n">frequencies</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v0</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">v1</span> <span class="ow">in</span> <span class="n">v0</span><span class="o">.</span><span class="n">itervalues</span><span class="p">():</span>
                <span class="n">vec</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">abs</span><span class="p">,</span> <span class="n">v1</span><span class="p">[</span><span class="s1">&#39;dynmat&#39;</span><span class="p">][</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">])</span>
                <span class="n">frequency</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">vec</span><span class="p">))</span> <span class="o">*</span> <span class="mf">2.</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mf">15.633302</span>  <span class="c1"># THz</span>
                <span class="n">frequencies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">frequency</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">frequencies</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nspecs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;returns the number of species&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nspecs</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">natoms</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;returns the number of atoms&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_natoms</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">ndisps</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;returns the number of displacements&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ndisps</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">masses</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;returns the list of atomic masses&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_masses</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_adjusted_fermi_level"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.get_adjusted_fermi_level">[docs]</a><span class="k">def</span> <span class="nf">get_adjusted_fermi_level</span><span class="p">(</span><span class="n">efermi</span><span class="p">,</span> <span class="n">cbm</span><span class="p">,</span> <span class="n">band_structure</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    When running a band structure computations the fermi level needs to be</span>
<span class="sd">    take from the static run that gave the charge density used for the non-self</span>
<span class="sd">    consistent band structure run. Sometimes this fermi level is however a</span>
<span class="sd">    little too low because of the mismatch between the uniform grid used in</span>
<span class="sd">    the static run and the band structure k-points (e.g., the VBM is on Gamma</span>
<span class="sd">    and the Gamma point is not in the uniform mesh). Here we use a procedure</span>
<span class="sd">    consisting in looking for energy levels higher than the static fermi level</span>
<span class="sd">    (but lower than the LUMO) if any of these levels make the band structure</span>
<span class="sd">    appears insulating and not metallic anymore, we keep this adjusted fermi</span>
<span class="sd">    level. This procedure has shown to detect correctly most insulators.</span>

<span class="sd">    Args:</span>
<span class="sd">        efermi (float): Fermi energy of the static run</span>
<span class="sd">        cbm (float): Conduction band minimum of the static run</span>
<span class="sd">        run_bandstructure: a band_structure object</span>

<span class="sd">    Returns:</span>
<span class="sd">        a new adjusted fermi level</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># make a working copy of band_structure</span>
    <span class="n">bs_working</span> <span class="o">=</span> <span class="n">BandStructureSymmLine</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">band_structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">())</span>
    <span class="k">if</span> <span class="n">bs_working</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
        <span class="n">e</span> <span class="o">=</span> <span class="n">efermi</span>
        <span class="k">while</span> <span class="n">e</span> <span class="o">&lt;</span> <span class="n">cbm</span><span class="p">:</span>
            <span class="n">e</span> <span class="o">+=</span> <span class="mf">0.01</span>
            <span class="n">bs_working</span><span class="o">.</span><span class="n">_efermi</span> <span class="o">=</span> <span class="n">e</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">bs_working</span><span class="o">.</span><span class="n">is_metal</span><span class="p">():</span>
                <span class="k">return</span> <span class="n">e</span>
    <span class="k">return</span> <span class="n">efermi</span></div>


<span class="c1"># a note to future confused people (i.e. myself):</span>
<span class="c1"># I use numpy.fromfile instead of scipy.io.FortranFile here because the records</span>
<span class="c1"># are of fixed length, so the record length is only written once. In fortran,</span>
<span class="c1"># this amounts to using open(..., form=&#39;unformatted&#39;, recl=recl_len). In</span>
<span class="c1"># constrast when you write UNK files, the record length is written at the</span>
<span class="c1"># beginning of each record. This allows you to use scipy.io.FortranFile. In</span>
<span class="c1"># fortran, this amounts to using open(..., form=&#39;unformatted&#39;) [i.e. no recl=].</span>
<div class="viewcode-block" id="Wavecar"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Wavecar">[docs]</a><span class="k">class</span> <span class="nc">Wavecar</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This is a class that contains the (pseudo-) wavefunctions from VASP.</span>

<span class="sd">    Coefficients are read from the given WAVECAR file and the corresponding</span>
<span class="sd">    G-vectors are generated using the algorithm developed in WaveTrans (see</span>
<span class="sd">    acknowledgments below). To understand how the wavefunctions are evaluated,</span>
<span class="sd">    please see the evaluate_wavefunc docstring.</span>

<span class="sd">    It should be noted that the pseudopotential augmentation is not included in</span>
<span class="sd">    the WAVECAR file. As a result, some caution should be exercised when</span>
<span class="sd">    deriving value from this information.</span>

<span class="sd">    The usefulness of this class is to allow the user to do projections or band</span>
<span class="sd">    unfolding style manipulations of the wavefunction. An example of this can</span>
<span class="sd">    be seen in the work of Shen et al. 2017</span>
<span class="sd">    (https://doi.org/10.1103/PhysRevMaterials.1.065001).</span>

<span class="sd">    .. attribute:: filename</span>

<span class="sd">        String of the input file (usually WAVECAR)</span>

<span class="sd">    .. attribute:: vasp_type</span>

<span class="sd">        String that determines VASP type the WAVECAR was generated with (either</span>
<span class="sd">        &#39;std&#39;, &#39;gam&#39;, or &#39;ncl&#39;)</span>

<span class="sd">    .. attribute:: nk</span>

<span class="sd">        Number of k-points from the WAVECAR</span>

<span class="sd">    .. attribute:: nb</span>

<span class="sd">        Number of bands per k-point</span>

<span class="sd">    .. attribute:: encut</span>

<span class="sd">        Energy cutoff (used to define G_{cut})</span>

<span class="sd">    .. attribute:: efermi</span>

<span class="sd">        Fermi energy</span>

<span class="sd">    .. attribute:: a</span>

<span class="sd">        Primitive lattice vectors of the cell (e.g. a_1 = self.a[0, :])</span>

<span class="sd">    .. attribute:: b</span>

<span class="sd">        Reciprocal lattice vectors of the cell (e.g. b_1 = self.b[0, :])</span>

<span class="sd">    .. attribute:: vol</span>

<span class="sd">        The volume of the unit cell in real space</span>

<span class="sd">    .. attribute:: kpoints</span>

<span class="sd">        The list of k-points read from the WAVECAR file</span>

<span class="sd">    .. attribute:: band_energy</span>

<span class="sd">        The list of band eigenenergies (and corresponding occupancies) for</span>
<span class="sd">        each kpoint, where the first index corresponds to the index of the</span>
<span class="sd">        k-point (e.g. self.band_energy[kp])</span>

<span class="sd">    .. attribute:: Gpoints</span>

<span class="sd">        The list of generated G-points for each k-point (a double list), which</span>
<span class="sd">        are used with the coefficients for each k-point and band to recreate</span>
<span class="sd">        the wavefunction (e.g. self.Gpoints[kp] is the list of G-points for</span>
<span class="sd">        k-point kp). The G-points depend on the k-point and reciprocal lattice</span>
<span class="sd">        and therefore are identical for each band at the same k-point. Each</span>
<span class="sd">        G-point is represented by integer multipliers (e.g. assuming</span>
<span class="sd">        Gpoints[kp][n] == [n_1, n_2, n_3], then</span>
<span class="sd">        G_n = n_1*b_1 + n_2*b_2 + n_3*b_3)</span>

<span class="sd">    .. attribute:: coeffs</span>

<span class="sd">        The list of coefficients for each k-point and band for reconstructing</span>
<span class="sd">        the wavefunction. For non-spin-polarized, the first index corresponds</span>
<span class="sd">        to the kpoint and the second corresponds to the band (e.g.</span>
<span class="sd">        self.coeffs[kp][b] corresponds to k-point kp and band b). For</span>
<span class="sd">        spin-polarized calculations, the first index is for the spin.</span>
<span class="sd">        If the calculation was non-collinear, then self.coeffs[kp][b] will have</span>
<span class="sd">        two columns (one for each component of the spinor).</span>

<span class="sd">    Acknowledgments:</span>
<span class="sd">        This code is based upon the Fortran program, WaveTrans, written by</span>
<span class="sd">        R. M. Feenstra and M. Widom from the Dept. of Physics at Carnegie</span>
<span class="sd">        Mellon University. To see the original work, please visit:</span>
<span class="sd">        https://www.andrew.cmu.edu/user/feenstra/wavetrans/</span>

<span class="sd">    Author: Mark Turiansky</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="s1">&#39;WAVECAR&#39;</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">precision</span><span class="o">=</span><span class="s1">&#39;normal&#39;</span><span class="p">,</span>
                 <span class="n">vasp_type</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Information is extracted from the given WAVECAR</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): input file (default: WAVECAR)</span>
<span class="sd">            verbose (bool): determines whether processing information is shown</span>
<span class="sd">            precision (str): determines how fine the fft mesh is (normal or</span>
<span class="sd">                             accurate), only the first letter matters</span>
<span class="sd">            vasp_type (str): determines the VASP type that is used, allowed</span>
<span class="sd">                             values are [&#39;std&#39;, &#39;gam&#39;, &#39;ncl&#39;]</span>
<span class="sd">                             (only first letter is required)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">vasp_type</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">vasp_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;s&#39;</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="s1">&#39;n&#39;</span><span class="p">]):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;invalid vasp_type </span><span class="si">{</span><span class="n">vasp_type</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span> <span class="o">=</span> <span class="n">vasp_type</span>

        <span class="c1"># c = 0.26246582250210965422</span>
        <span class="c1"># 2m/hbar^2 in agreement with VASP</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_C</span> <span class="o">=</span> <span class="mf">0.262465831</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="c1"># read the header information</span>
            <span class="n">recl</span><span class="p">,</span> <span class="n">spin</span><span class="p">,</span> <span class="n">rtag</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> \
                <span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;recl=</span><span class="si">{}</span><span class="s1">, spin=</span><span class="si">{}</span><span class="s1">, rtag=</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">recl</span><span class="p">,</span> <span class="n">spin</span><span class="p">,</span> <span class="n">rtag</span><span class="p">))</span>
            <span class="n">recl8</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">recl</span> <span class="o">/</span> <span class="mi">8</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="o">=</span> <span class="n">spin</span>

            <span class="c1"># check to make sure we have precision correct</span>
            <span class="k">if</span> <span class="n">rtag</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">45200</span><span class="p">,</span> <span class="mi">45210</span><span class="p">,</span> <span class="mi">53300</span><span class="p">,</span> <span class="mi">53310</span><span class="p">):</span>
                <span class="c1"># note that rtag=45200 and 45210 may not work if file was actually</span>
                <span class="c1"># generated by old version of VASP, since that would write eigenvalues</span>
                <span class="c1"># and occupations in way that does not span FORTRAN records, but</span>
                <span class="c1"># reader below appears to assume that record boundaries can be ignored</span>
                <span class="c1"># (see OUTWAV vs. OUTWAV_4 in vasp fileio.F)</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;invalid rtag of </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">rtag</span><span class="p">))</span>

            <span class="c1"># padding to end of fortran REC=1</span>
            <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="p">(</span><span class="n">recl8</span> <span class="o">-</span> <span class="mi">3</span><span class="p">))</span>

            <span class="c1"># extract kpoint, bands, energy, and lattice information</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nk</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">encut</span> <span class="o">=</span> \
                <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">9</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;kpoints = </span><span class="si">{}</span><span class="s1">, bands = </span><span class="si">{}</span><span class="s1">, energy cutoff = </span><span class="si">{}</span><span class="s1">, fermi &#39;</span>
                      <span class="s1">&#39;energy= </span><span class="si">{:.04f}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nk</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">encut</span><span class="p">,</span>
                                                 <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">))</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;primitive lattice vectors = </span><span class="se">\n</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">))</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">vol</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span>
                              <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:],</span> <span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:]))</span>
            <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;volume = </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vol</span><span class="p">))</span>

            <span class="c1"># calculate reciprocal lattice</span>
            <span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:],</span> <span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:]),</span>
                          <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:],</span> <span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:]),</span>
                          <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="bp">self</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:])])</span>
            <span class="n">b</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">b</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">vol</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">b</span>
            <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;reciprocal lattice vectors = </span><span class="se">\n</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">b</span><span class="p">))</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;reciprocal lattice vector magnitudes = </span><span class="se">\n</span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span>
                      <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)))</span>

            <span class="c1"># calculate maximum number of b vectors in each direction</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_generate_nbmax</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;max number of G values = </span><span class="si">{}</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ng</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span> <span class="o">*</span> <span class="mi">3</span> <span class="k">if</span> <span class="n">precision</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;n&#39;</span> <span class="k">else</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span> <span class="o">*</span> <span class="mi">4</span>

            <span class="c1"># padding to end of fortran REC=2</span>
            <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="n">recl8</span> <span class="o">-</span> <span class="mi">13</span><span class="p">)</span>

            <span class="c1"># reading records</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span> <span class="o">=</span> <span class="p">[</span><span class="kc">None</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nk</span><span class="p">)]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">if</span> <span class="n">spin</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span> <span class="o">=</span> <span class="p">[[[</span><span class="kc">None</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">)]</span>
                                <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nk</span><span class="p">)]</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">spin</span><span class="p">)]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">band_energy</span> <span class="o">=</span> <span class="p">[[]</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">spin</span><span class="p">)]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span> <span class="o">=</span> <span class="p">[[</span><span class="kc">None</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">)]</span>
                               <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nk</span><span class="p">)]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">band_energy</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">for</span> <span class="n">ispin</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;reading spin </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ispin</span><span class="p">))</span>

                <span class="k">for</span> <span class="n">ink</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nk</span><span class="p">):</span>
                    <span class="c1"># information for this kpoint</span>
                    <span class="n">nplane</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
                    <span class="n">kpoint</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>

                    <span class="k">if</span> <span class="n">ispin</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">kpoint</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">assert</span> <span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">],</span> <span class="n">kpoint</span><span class="p">)</span>

                    <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;kpoint </span><span class="si">{: 4}</span><span class="s1"> with </span><span class="si">{: 5}</span><span class="s1"> plane waves at </span><span class="si">{}</span><span class="s1">&#39;</span>
                              <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ink</span><span class="p">,</span> <span class="n">nplane</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">))</span>

                    <span class="c1"># energy and occupation information</span>
                    <span class="n">enocc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span>
                                        <span class="n">count</span><span class="o">=</span><span class="mi">3</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">spin</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">band_energy</span><span class="p">[</span><span class="n">ispin</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">enocc</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">band_energy</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">enocc</span><span class="p">)</span>

                    <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;enocc =</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">enocc</span><span class="p">[:,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span>

                    <span class="c1"># padding to end of record that contains nplane, kpoints, evals and occs</span>
                    <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="p">(</span><span class="n">recl8</span> <span class="o">-</span> <span class="mi">4</span> <span class="o">-</span> <span class="mi">3</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">)</span> <span class="o">%</span> <span class="n">recl8</span><span class="p">)</span>

                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">],</span> <span class="n">extra_gpoints</span><span class="p">,</span> <span class="n">extra_coeff_inds</span><span class="p">)</span> <span class="o">=</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">_generate_G_points</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">gamma</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">])</span> <span class="o">==</span> <span class="n">nplane</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span> <span class="o">=</span> <span class="s1">&#39;gam&#39;</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">],</span> <span class="n">extra_gpoints</span><span class="p">,</span> <span class="n">extra_coeff_inds</span><span class="p">)</span> <span class="o">=</span> \
                                <span class="bp">self</span><span class="o">.</span><span class="n">_generate_G_points</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">gamma</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span> <span class="o">=</span> \
                                <span class="s1">&#39;std&#39;</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">])</span> <span class="o">==</span> <span class="n">nplane</span> <span class="k">else</span> <span class="s1">&#39;ncl&#39;</span>

                        <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
                            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">determined vasp_type =&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span><span class="p">,</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">],</span> <span class="n">extra_gpoints</span><span class="p">,</span> <span class="n">extra_coeff_inds</span><span class="p">)</span> <span class="o">=</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">_generate_G_points</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">gamma</span><span class="o">=</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;g&#39;</span><span class="p">))</span>

                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">])</span> <span class="o">!=</span> <span class="n">nplane</span> <span class="ow">and</span> <span class="mi">2</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">])</span> <span class="o">!=</span> <span class="n">nplane</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Incorrect value of vasp_type given (</span><span class="si">{</span><span class="n">vasp_type</span><span class="si">}</span><span class="s1">).&#39;</span>
                                         <span class="s1">&#39; Please open an issue if you are certain this WAVECAR&#39;</span>
                                         <span class="s1">&#39; was generated with the given vasp_type.&#39;</span><span class="p">)</span>

                    <span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">ink</span><span class="p">]</span> <span class="o">+</span> <span class="n">extra_gpoints</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">)</span>

                    <span class="c1"># extract coefficients</span>
                    <span class="k">for</span> <span class="n">inb</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">):</span>
                        <span class="k">if</span> <span class="n">rtag</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">45200</span><span class="p">,</span> <span class="mi">53300</span><span class="p">):</span>
                            <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="n">nplane</span><span class="p">)</span>
                            <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="n">recl8</span> <span class="o">-</span> <span class="n">nplane</span><span class="p">)</span>
                        <span class="k">elif</span> <span class="n">rtag</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">45210</span><span class="p">,</span> <span class="mi">53310</span><span class="p">):</span>
                            <span class="c1"># this should handle double precision coefficients</span>
                            <span class="c1"># but I don&#39;t have a WAVECAR to test it with</span>
                            <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex128</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="n">nplane</span><span class="p">)</span>
                            <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="n">recl8</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">nplane</span><span class="p">)</span>

                        <span class="n">extra_coeffs</span> <span class="o">=</span> <span class="p">[]</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">extra_coeff_inds</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                            <span class="c1"># reconstruct extra coefficients missing from gamma-only executable WAVECAR</span>
                            <span class="k">for</span> <span class="n">G_ind</span> <span class="ow">in</span> <span class="n">extra_coeff_inds</span><span class="p">:</span>
                                <span class="c1"># no idea where this factor of sqrt(2) comes from, but empirically</span>
                                <span class="c1"># it appears to be necessary</span>
                                <span class="n">data</span><span class="p">[</span><span class="n">G_ind</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
                                <span class="n">extra_coeffs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">conj</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">G_ind</span><span class="p">]))</span>

                        <span class="k">if</span> <span class="n">spin</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">ispin</span><span class="p">][</span><span class="n">ink</span><span class="p">][</span><span class="n">inb</span><span class="p">]</span> <span class="o">=</span> \
                                <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">+</span> <span class="n">extra_coeffs</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex64</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">ink</span><span class="p">][</span><span class="n">inb</span><span class="p">]</span> <span class="o">=</span> \
                                <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">+</span> <span class="n">extra_coeffs</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex128</span><span class="p">)</span>

                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;n&#39;</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">ink</span><span class="p">][</span><span class="n">inb</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">nplane</span><span class="o">//</span><span class="mi">2</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_generate_nbmax</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Helper function that determines maximum number of b vectors for</span>
<span class="sd">        each direction.</span>

<span class="sd">        This algorithm is adapted from WaveTrans (see Class docstring). There</span>
<span class="sd">        should be no reason for this function to be called outside of</span>
<span class="sd">        initialization.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">bmag</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span>

        <span class="c1"># calculate maximum integers in each direction for G</span>
        <span class="n">phi12</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arccos</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:])</span> <span class="o">/</span> <span class="p">(</span><span class="n">bmag</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">bmag</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
        <span class="n">sphi123</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:],</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:]))</span> \
            <span class="o">/</span> <span class="p">(</span><span class="n">bmag</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:])))</span>
        <span class="n">nbmaxA</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">encut</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_C</span><span class="p">)</span> <span class="o">/</span> <span class="n">bmag</span>
        <span class="n">nbmaxA</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phi12</span><span class="p">))</span>
        <span class="n">nbmaxA</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phi12</span><span class="p">))</span>
        <span class="n">nbmaxA</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">sphi123</span><span class="p">)</span>
        <span class="n">nbmaxA</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="n">phi13</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arccos</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:])</span> <span class="o">/</span> <span class="p">(</span><span class="n">bmag</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">bmag</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
        <span class="n">sphi123</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:],</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:]))</span> \
            <span class="o">/</span> <span class="p">(</span><span class="n">bmag</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:])))</span>
        <span class="n">nbmaxB</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">encut</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_C</span><span class="p">)</span> <span class="o">/</span> <span class="n">bmag</span>
        <span class="n">nbmaxB</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phi13</span><span class="p">))</span>
        <span class="n">nbmaxB</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">sphi123</span><span class="p">)</span>
        <span class="n">nbmaxB</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phi13</span><span class="p">))</span>
        <span class="n">nbmaxB</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="n">phi23</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arccos</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:])</span> <span class="o">/</span> <span class="p">(</span><span class="n">bmag</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">bmag</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
        <span class="n">sphi123</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:]))</span> \
            <span class="o">/</span> <span class="p">(</span><span class="n">bmag</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:],</span> <span class="n">b</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:])))</span>
        <span class="n">nbmaxC</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">encut</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_C</span><span class="p">)</span> <span class="o">/</span> <span class="n">bmag</span>
        <span class="n">nbmaxC</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">sphi123</span><span class="p">)</span>
        <span class="n">nbmaxC</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phi23</span><span class="p">))</span>
        <span class="n">nbmaxC</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phi23</span><span class="p">))</span>
        <span class="n">nbmaxC</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">([</span><span class="n">nbmaxA</span><span class="p">,</span> <span class="n">nbmaxB</span><span class="p">,</span> <span class="n">nbmaxC</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_generate_G_points</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">gamma</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">List</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">List</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Helper function to generate G-points based on nbmax.</span>

<span class="sd">        This function iterates over possible G-point values and determines</span>
<span class="sd">        if the energy is less than G_{cut}. Valid values are appended to</span>
<span class="sd">        the output array. This function should not be called outside of</span>
<span class="sd">        initialization.</span>

<span class="sd">        Args:</span>
<span class="sd">            kpoint (np.array): the array containing the current k-point value</span>
<span class="sd">            gamma (bool): determines if G points for gamma-point only executable</span>
<span class="sd">                          should be generated</span>

<span class="sd">        Returns:</span>
<span class="sd">            a list containing valid G-points</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">gamma</span><span class="p">:</span>
            <span class="n">kmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">kmax</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span>

        <span class="n">gpoints</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">extra_gpoints</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">extra_coeff_inds</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">G_ind</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
            <span class="n">i3</span> <span class="o">=</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">else</span> <span class="n">i</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
                <span class="n">j2</span> <span class="o">=</span> <span class="n">j</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">j</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">else</span> <span class="n">j</span>
                <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">kmax</span><span class="p">):</span>
                    <span class="n">k1</span> <span class="o">=</span> <span class="n">k</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">if</span> <span class="n">k</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbmax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">else</span> <span class="n">k</span>
                    <span class="k">if</span> <span class="n">gamma</span> <span class="ow">and</span> <span class="p">((</span><span class="n">k1</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">j2</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">k1</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">j2</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">i3</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)):</span>
                        <span class="k">continue</span>
                    <span class="n">G</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">k1</span><span class="p">,</span> <span class="n">j2</span><span class="p">,</span> <span class="n">i3</span><span class="p">])</span>
                    <span class="n">v</span> <span class="o">=</span> <span class="n">kpoint</span> <span class="o">+</span> <span class="n">G</span>
                    <span class="n">g</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">))</span>
                    <span class="n">E</span> <span class="o">=</span> <span class="n">g</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">_C</span>
                    <span class="k">if</span> <span class="n">E</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">encut</span><span class="p">:</span>
                        <span class="n">gpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">G</span><span class="p">)</span>
                        <span class="k">if</span> <span class="n">gamma</span> <span class="ow">and</span> <span class="p">(</span><span class="n">k1</span><span class="p">,</span> <span class="n">j2</span><span class="p">,</span> <span class="n">i3</span><span class="p">)</span> <span class="o">!=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span>
                            <span class="n">extra_gpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="o">-</span><span class="n">G</span><span class="p">)</span>
                            <span class="n">extra_coeff_inds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">G_ind</span><span class="p">)</span>
                        <span class="n">G_ind</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">gpoints</span><span class="p">,</span> <span class="n">extra_gpoints</span><span class="p">,</span> <span class="n">extra_coeff_inds</span><span class="p">)</span>

<div class="viewcode-block" id="Wavecar.evaluate_wavefunc"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Wavecar.evaluate_wavefunc">[docs]</a>    <span class="k">def</span> <span class="nf">evaluate_wavefunc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">band</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">r</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span>
                          <span class="n">spin</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">spinor</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">complex64</span><span class="p">:</span>
        <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Evaluates the wavefunction for a given position, r.</span>

<span class="sd">        The wavefunction is given by the k-point and band. It is evaluated</span>
<span class="sd">        at the given position by summing over the components. Formally,</span>

<span class="sd">        \psi_n^k (r) = \sum_{i=1}^N c_i^{n,k} \exp (i (k + G_i^{n,k}) \cdot r)</span>

<span class="sd">        where \psi_n^k is the wavefunction for the nth band at k-point k, N is</span>
<span class="sd">        the number of plane waves, c_i^{n,k} is the ith coefficient that</span>
<span class="sd">        corresponds to the nth band and k-point k, and G_i^{n,k} is the ith</span>
<span class="sd">        G-point corresponding to k-point k.</span>

<span class="sd">        NOTE: This function is very slow; a discrete fourier transform is the</span>
<span class="sd">        preferred method of evaluation (see Wavecar.fft_mesh).</span>

<span class="sd">        Args:</span>
<span class="sd">            kpoint (int): the index of the kpoint where the wavefunction</span>
<span class="sd">                            will be evaluated</span>
<span class="sd">            band (int): the index of the band where the wavefunction will be</span>
<span class="sd">                            evaluated</span>
<span class="sd">            r (np.array): the position where the wavefunction will be evaluated</span>
<span class="sd">            spin (int):  spin index for the desired wavefunction (only for</span>
<span class="sd">                            ISPIN = 2, default = 0)</span>
<span class="sd">            spinor (int): component of the spinor that is evaluated (only used</span>
<span class="sd">                            if vasp_type == &#39;ncl&#39;)</span>
<span class="sd">        Returns:</span>
<span class="sd">            a complex value corresponding to the evaluation of the wavefunction</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">kpoint</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">kpoint</span><span class="p">]</span>
        <span class="n">u</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">),</span> <span class="n">r</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;n&#39;</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">kpoint</span><span class="p">][</span><span class="n">band</span><span class="p">][</span><span class="n">spinor</span><span class="p">,</span> <span class="p">:]</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">kpoint</span><span class="p">][</span><span class="n">band</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">kpoint</span><span class="p">][</span><span class="n">band</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="mi">1</span><span class="n">j</span> <span class="o">*</span> <span class="n">u</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex64</span><span class="p">)))</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vol</span><span class="p">)</span></div>

<div class="viewcode-block" id="Wavecar.fft_mesh"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Wavecar.fft_mesh">[docs]</a>    <span class="k">def</span> <span class="nf">fft_mesh</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">band</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">spin</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">spinor</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
                 <span class="n">shift</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Places the coefficients of a wavefunction onto an fft mesh.</span>

<span class="sd">        Once the mesh has been obtained, a discrete fourier transform can be</span>
<span class="sd">        used to obtain real-space evaluation of the wavefunction. The output</span>
<span class="sd">        of this function can be passed directly to numpy&#39;s fft function. For</span>
<span class="sd">        example:</span>

<span class="sd">            mesh = Wavecar(&#39;WAVECAR&#39;).fft_mesh(kpoint, band)</span>
<span class="sd">            evals = np.fft.ifftn(mesh)</span>

<span class="sd">        Args:</span>
<span class="sd">            kpoint (int): the index of the kpoint where the wavefunction</span>
<span class="sd">                            will be evaluated</span>
<span class="sd">            band (int): the index of the band where the wavefunction will be</span>
<span class="sd">                            evaluated</span>
<span class="sd">            spin (int):  the spin of the wavefunction for the desired</span>
<span class="sd">                            wavefunction (only for ISPIN = 2, default = 0)</span>
<span class="sd">            spinor (int): component of the spinor that is evaluated (only used</span>
<span class="sd">                            if vasp_type == &#39;ncl&#39;)</span>
<span class="sd">            shift (bool): determines if the zero frequency coefficient is</span>
<span class="sd">                            placed at index (0, 0, 0) or centered</span>
<span class="sd">        Returns:</span>
<span class="sd">            a numpy ndarray representing the 3D mesh of coefficients</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;n&#39;</span><span class="p">:</span>
            <span class="n">tcoeffs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">kpoint</span><span class="p">][</span><span class="n">band</span><span class="p">][</span><span class="n">spinor</span><span class="p">,</span> <span class="p">:]</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">tcoeffs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">spin</span><span class="p">][</span><span class="n">kpoint</span><span class="p">][</span><span class="n">band</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">tcoeffs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">coeffs</span><span class="p">[</span><span class="n">kpoint</span><span class="p">][</span><span class="n">band</span><span class="p">]</span>

        <span class="n">mesh</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ng</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">gp</span><span class="p">,</span> <span class="n">coeff</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Gpoints</span><span class="p">[</span><span class="n">kpoint</span><span class="p">],</span> <span class="n">tcoeffs</span><span class="p">):</span>
            <span class="n">t</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">gp</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ng</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">))</span>
            <span class="n">mesh</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">=</span> <span class="n">coeff</span>

        <span class="k">if</span> <span class="n">shift</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftshift</span><span class="p">(</span><span class="n">mesh</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">mesh</span></div>

<div class="viewcode-block" id="Wavecar.get_parchg"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Wavecar.get_parchg">[docs]</a>    <span class="k">def</span> <span class="nf">get_parchg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">poscar</span><span class="p">:</span> <span class="n">Poscar</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">band</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                   <span class="n">spin</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">spinor</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                   <span class="n">phase</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> <span class="n">scale</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Chgcar</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates a Chgcar object, which is the charge density of the specified</span>
<span class="sd">        wavefunction.</span>

<span class="sd">        This function generates a Chgcar object with the charge density of the</span>
<span class="sd">        wavefunction specified by band and kpoint (and spin, if the WAVECAR</span>
<span class="sd">        corresponds to a spin-polarized calculation). The phase tag is a</span>
<span class="sd">        feature that is not present in VASP. For a real wavefunction, the phase</span>
<span class="sd">        tag being turned on means that the charge density is multiplied by the</span>
<span class="sd">        sign of the wavefunction at that point in space. A warning is generated</span>
<span class="sd">        if the phase tag is on and the chosen kpoint is not Gamma.</span>

<span class="sd">        Note: Augmentation from the PAWs is NOT included in this function. The</span>
<span class="sd">        maximal charge density will differ from the PARCHG from VASP, but the</span>
<span class="sd">        qualitative shape of the charge density will match.</span>

<span class="sd">        Args:</span>
<span class="sd">            poscar (pymatgen.io.vasp.inputs.Poscar): Poscar object that has the</span>
<span class="sd">                structure associated with the WAVECAR file</span>
<span class="sd">            kpoint (int): the index of the kpoint for the wavefunction</span>
<span class="sd">            band (int): the index of the band for the wavefunction</span>
<span class="sd">            spin (int): optional argument to specify the spin. If the Wavecar</span>
<span class="sd">                has ISPIN = 2, spin is None generates a Chgcar with total spin</span>
<span class="sd">                and magnetization, and spin == {0, 1} specifies just the spin</span>
<span class="sd">                up or down component.</span>
<span class="sd">            spinor (int): optional argument to specify the spinor component</span>
<span class="sd">                for noncollinear data wavefunctions (allowed values of None,</span>
<span class="sd">                0, or 1)</span>
<span class="sd">            phase (bool): flag to determine if the charge density is multiplied</span>
<span class="sd">                by the sign of the wavefunction. Only valid for real</span>
<span class="sd">                wavefunctions.</span>
<span class="sd">            scale (int): scaling for the FFT grid. The default value of 2 is at</span>
<span class="sd">                least as fine as the VASP default.</span>
<span class="sd">        Returns:</span>
<span class="sd">            a pymatgen.io.vasp.outputs.Chgcar object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">phase</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="p">[</span><span class="n">kpoint</span><span class="p">]</span> <span class="o">==</span> <span class="mf">0.</span><span class="p">):</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s1">&#39;phase == True should only be used for the Gamma &#39;</span>
                          <span class="s1">&#39;kpoint! I hope you know what you</span><span class="se">\&#39;</span><span class="s1">re doing!&#39;</span><span class="p">)</span>

        <span class="c1"># scaling of ng for the fft grid, need to restore value at the end</span>
        <span class="n">temp_ng</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ng</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ng</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ng</span> <span class="o">*</span> <span class="n">scale</span>
        <span class="n">N</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">prod</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ng</span><span class="p">)</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">spin</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">spin</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">wfr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="n">spin</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                <span class="n">den</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">conj</span><span class="p">(</span><span class="n">wfr</span><span class="p">)</span> <span class="o">*</span> <span class="n">wfr</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">phase</span><span class="p">:</span>
                    <span class="n">den</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">real</span><span class="p">(</span><span class="n">wfr</span><span class="p">))</span> <span class="o">*</span> <span class="n">den</span>
                <span class="n">data</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">den</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">wfr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                <span class="n">denup</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">conj</span><span class="p">(</span><span class="n">wfr</span><span class="p">)</span> <span class="o">*</span> <span class="n">wfr</span><span class="p">)</span>
                <span class="n">wfr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                <span class="n">dendn</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">conj</span><span class="p">(</span><span class="n">wfr</span><span class="p">)</span> <span class="o">*</span> <span class="n">wfr</span><span class="p">)</span>
                <span class="n">data</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">denup</span> <span class="o">+</span> <span class="n">dendn</span>
                <span class="n">data</span><span class="p">[</span><span class="s1">&#39;diff&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">denup</span> <span class="o">-</span> <span class="n">dendn</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">spinor</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">wfr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">spinor</span><span class="o">=</span><span class="n">spinor</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                <span class="n">den</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">conj</span><span class="p">(</span><span class="n">wfr</span><span class="p">)</span> <span class="o">*</span> <span class="n">wfr</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">wfr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">spinor</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                <span class="n">wfr_t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">kpoint</span><span class="p">,</span> <span class="n">band</span><span class="p">,</span> <span class="n">spinor</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                <span class="n">den</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">conj</span><span class="p">(</span><span class="n">wfr</span><span class="p">)</span> <span class="o">*</span> <span class="n">wfr</span><span class="p">)</span>
                <span class="n">den</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">conj</span><span class="p">(</span><span class="n">wfr_t</span><span class="p">)</span> <span class="o">*</span> <span class="n">wfr_t</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">phase</span> <span class="ow">and</span> <span class="ow">not</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;n&#39;</span> <span class="ow">and</span> <span class="n">spinor</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">):</span>
                <span class="n">den</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">real</span><span class="p">(</span><span class="n">wfr</span><span class="p">))</span> <span class="o">*</span> <span class="n">den</span>
            <span class="n">data</span><span class="p">[</span><span class="s1">&#39;total&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">den</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">ng</span> <span class="o">=</span> <span class="n">temp_ng</span>
        <span class="k">return</span> <span class="n">Chgcar</span><span class="p">(</span><span class="n">poscar</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></div>

<div class="viewcode-block" id="Wavecar.write_unks"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Wavecar.write_unks">[docs]</a>    <span class="k">def</span> <span class="nf">write_unks</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">directory</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Write the UNK files to the given directory.</span>

<span class="sd">        Writes the cell-periodic part of the bloch wavefunctions from the</span>
<span class="sd">        WAVECAR file to each of the UNK files. There will be one UNK file for</span>
<span class="sd">        each of the kpoints in the WAVECAR file.</span>

<span class="sd">        Note:</span>
<span class="sd">            wannier90 expects the full kpoint grid instead of the symmetry-</span>
<span class="sd">            reduced one that VASP stores the wavefunctions on. You should run</span>
<span class="sd">            a nscf calculation with ISYM=0 to obtain the correct grid.</span>

<span class="sd">        Args:</span>
<span class="sd">            directory (str): directory where the UNK files are written</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">out_dir</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">directory</span><span class="p">)</span><span class="o">.</span><span class="n">expanduser</span><span class="p">()</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">out_dir</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
            <span class="n">out_dir</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">elif</span> <span class="ow">not</span> <span class="n">out_dir</span><span class="o">.</span><span class="n">is_dir</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;invalid directory&#39;</span><span class="p">)</span>

        <span class="n">N</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">prod</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ng</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">ik</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nk</span><span class="p">):</span>
            <span class="n">fname</span> <span class="o">=</span> <span class="sa">f</span><span class="s1">&#39;UNK</span><span class="si">{</span><span class="n">ik</span><span class="o">+</span><span class="mi">1</span><span class="si">:</span><span class="s1">05d</span><span class="si">}</span><span class="s1">.&#39;</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vasp_type</span><span class="o">.</span><span class="n">lower</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;n&#39;</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">ng</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex128</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">ib</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">):</span>
                    <span class="n">data</span><span class="p">[</span><span class="n">ib</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">:,</span> <span class="p">:,</span> <span class="p">:]</span> <span class="o">=</span> \
                        <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">ik</span><span class="p">,</span> <span class="n">ib</span><span class="p">,</span> <span class="n">spinor</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                    <span class="n">data</span><span class="p">[</span><span class="n">ib</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="p">:,</span> <span class="p">:,</span> <span class="p">:]</span> <span class="o">=</span> \
                        <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">ik</span><span class="p">,</span> <span class="n">ib</span><span class="p">,</span> <span class="n">spinor</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                <span class="n">Unk</span><span class="p">(</span><span class="n">ik</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span><span class="o">.</span><span class="n">write_file</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">out_dir</span> <span class="o">/</span> <span class="p">(</span><span class="n">fname</span> <span class="o">+</span> <span class="s1">&#39;NC&#39;</span><span class="p">)))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">,</span> <span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">ng</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">complex128</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">ispin</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">spin</span><span class="p">):</span>
                    <span class="k">for</span> <span class="n">ib</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb</span><span class="p">):</span>
                        <span class="n">data</span><span class="p">[</span><span class="n">ib</span><span class="p">,</span> <span class="p">:,</span> <span class="p">:,</span> <span class="p">:]</span> <span class="o">=</span> \
                            <span class="n">np</span><span class="o">.</span><span class="n">fft</span><span class="o">.</span><span class="n">ifftn</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fft_mesh</span><span class="p">(</span><span class="n">ik</span><span class="p">,</span> <span class="n">ib</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="n">ispin</span><span class="p">))</span> <span class="o">*</span> <span class="n">N</span>
                    <span class="n">Unk</span><span class="p">(</span><span class="n">ik</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span><span class="o">.</span><span class="n">write_file</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">out_dir</span> <span class="o">/</span> <span class="p">(</span><span class="n">fname</span> <span class="o">+</span> <span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">ispin</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)))</span></div></div>


<div class="viewcode-block" id="Eigenval"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Eigenval">[docs]</a><span class="k">class</span> <span class="nc">Eigenval</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for reading EIGENVAL file.</span>

<span class="sd">    .. attribute:: filename</span>

<span class="sd">        string containing input filename</span>

<span class="sd">    .. attribute:: occu_tol</span>

<span class="sd">        tolerance for determining occupation in band properties</span>

<span class="sd">    .. attribute:: ispin</span>

<span class="sd">        spin polarization tag (int)</span>

<span class="sd">    .. attribute:: nelect</span>

<span class="sd">        number of electrons</span>

<span class="sd">    .. attribute:: nkpt</span>

<span class="sd">        number of kpoints</span>

<span class="sd">    .. attribute:: nbands</span>

<span class="sd">        number of bands</span>

<span class="sd">    .. attribute:: kpoints</span>

<span class="sd">        list of kpoints</span>

<span class="sd">    .. attribute:: kpoints_weights</span>

<span class="sd">        weights of each kpoint in the BZ, should sum to 1.</span>

<span class="sd">    .. attribute:: eigenvalues</span>

<span class="sd">        Eigenvalues as a dict of {(spin): np.ndarray(shape=(nkpt, nbands, 2))}.</span>
<span class="sd">        This representation is based on actual ordering in VASP and is meant as</span>
<span class="sd">        an intermediate representation to be converted into proper objects. The</span>
<span class="sd">        kpoint index is 0-based (unlike the 1-based indexing in VASP).</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">occu_tol</span><span class="o">=</span><span class="mf">1e-8</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reads input from filename to construct Eigenval object</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str):     filename of EIGENVAL to read in</span>
<span class="sd">            occu_tol (float):   tolerance for determining band gap</span>

<span class="sd">        Returns:</span>
<span class="sd">            a pymatgen.io.vasp.outputs.Eigenval object</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">occu_tol</span> <span class="o">=</span> <span class="n">occu_tol</span>

        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ispin</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

            <span class="c1"># useless header information</span>
            <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span>
                <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">nelect</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nkpt</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbands</span> <span class="o">=</span> \
                <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()))</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">kpoints_weights</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ispin</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span> <span class="o">=</span> \
                    <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">nkpt</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbands</span><span class="p">,</span> <span class="mi">2</span><span class="p">)),</span>
                     <span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">nkpt</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbands</span><span class="p">,</span> <span class="mi">2</span><span class="p">))}</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span> <span class="o">=</span> \
                    <span class="p">{</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">nkpt</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbands</span><span class="p">,</span> <span class="mi">2</span><span class="p">))}</span>

            <span class="n">ikpt</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;(\s+[\-+0-9eE.]+)</span><span class="si">{4}</span><span class="s1">&#39;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">line</span><span class="p">)):</span>
                    <span class="n">ikpt</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="n">kpt</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()))</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">kpoints</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">kpt</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">kpoints_weights</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">kpt</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nbands</span><span class="p">):</span>
                        <span class="n">sl</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()))</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">sl</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">ikpt</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">sl</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">ikpt</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">sl</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
                        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">sl</span><span class="p">)</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">ikpt</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">sl</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">ikpt</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">sl</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][</span><span class="n">ikpt</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">sl</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][</span><span class="n">ikpt</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">sl</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">eigenvalue_band_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Band properties from the eigenvalues as a tuple,</span>
<span class="sd">        (band gap, cbm, vbm, is_band_gap_direct).</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">vbm</span> <span class="o">=</span> <span class="o">-</span><span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>
        <span class="n">vbm_kpoint</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">cbm</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>
        <span class="n">cbm_kpoint</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">eigenvalues</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
                <span class="k">for</span> <span class="p">(</span><span class="n">eigenval</span><span class="p">,</span> <span class="n">occu</span><span class="p">)</span> <span class="ow">in</span> <span class="n">val</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">occu</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">occu_tol</span> <span class="ow">and</span> <span class="n">eigenval</span> <span class="o">&gt;</span> <span class="n">vbm</span><span class="p">:</span>
                        <span class="n">vbm</span> <span class="o">=</span> <span class="n">eigenval</span>
                        <span class="n">vbm_kpoint</span> <span class="o">=</span> <span class="n">k</span>
                    <span class="k">elif</span> <span class="n">occu</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">occu_tol</span> <span class="ow">and</span> <span class="n">eigenval</span> <span class="o">&lt;</span> <span class="n">cbm</span><span class="p">:</span>
                        <span class="n">cbm</span> <span class="o">=</span> <span class="n">eigenval</span>
                        <span class="n">cbm_kpoint</span> <span class="o">=</span> <span class="n">k</span>
        <span class="k">return</span> <span class="nb">max</span><span class="p">(</span><span class="n">cbm</span> <span class="o">-</span> <span class="n">vbm</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">cbm</span><span class="p">,</span> <span class="n">vbm</span><span class="p">,</span> <span class="n">vbm_kpoint</span> <span class="o">==</span> <span class="n">cbm_kpoint</span></div>


<div class="viewcode-block" id="Wavederf"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Wavederf">[docs]</a><span class="k">class</span> <span class="nc">Wavederf</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for reading a WAVEDERF file.</span>

<span class="sd">    Note: This file is only produced when LOPTICS is true AND vasp has been</span>
<span class="sd">    recompiled after uncommenting the line that calls</span>
<span class="sd">    WRT_CDER_BETWEEN_STATES_FORMATTED in linear_optics.F</span>

<span class="sd">    .. attribute:: data</span>

<span class="sd">        A numpy array containing the WAVEDERF data of the form below. It should</span>
<span class="sd">        be noted that VASP uses 1-based indexing for bands, but this is</span>
<span class="sd">        converted to 0-based numpy array indexing.</span>

<span class="sd">        For each kpoint (in the same order as in IBZKPT), and for each pair of</span>
<span class="sd">        bands:</span>

<span class="sd">            [ #kpoint index</span>
<span class="sd">             [ #band 1 index</span>
<span class="sd">              [ #band 2 index</span>
<span class="sd">               [cdum_x_real, cdum_x_imag, cdum_y_real, cdum_y_imag, cdum_z_real, cdum_z_imag]</span>
<span class="sd">              ]</span>
<span class="sd">             ]</span>
<span class="sd">            ]</span>

<span class="sd">        This structure follows the file format. Numpy array methods can be used</span>
<span class="sd">        to fetch data in a more useful way (e.g., get matrix elements between</span>
<span class="sd">        wo specific bands at each kpoint, fetch x/y/z components,</span>
<span class="sd">        real/imaginary parts, abs/phase, etc. )</span>

<span class="sd">    Author: Miguel Dias Costa</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filename: Name of file containing WAVEDERF.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">zopen</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">header</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
            <span class="n">nb_kpoints</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">header</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">nb_bands</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">header</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
            <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nb_kpoints</span><span class="p">,</span> <span class="n">nb_bands</span><span class="p">,</span> <span class="n">nb_bands</span><span class="p">,</span> <span class="mi">6</span><span class="p">))</span>
            <span class="k">for</span> <span class="n">ik</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nb_kpoints</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">ib1</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nb_bands</span><span class="p">):</span>
                    <span class="k">for</span> <span class="n">ib2</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nb_bands</span><span class="p">):</span>
                        <span class="c1"># each line in the file includes besides the band</span>
                        <span class="c1"># indexes, which are redundant, each band&#39;s energy</span>
                        <span class="c1"># and occupation, which are already available elsewhere,</span>
                        <span class="c1"># so we store only the 6 matrix elements after this 6</span>
                        <span class="c1"># redundant values</span>
                        <span class="n">data</span><span class="p">[</span><span class="n">ik</span><span class="p">][</span><span class="n">ib1</span><span class="p">][</span><span class="n">ib2</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">element</span><span class="p">)</span>
                                              <span class="k">for</span> <span class="n">element</span> <span class="ow">in</span> <span class="n">f</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">6</span><span class="p">:]]</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_nb_kpoints</span> <span class="o">=</span> <span class="n">nb_kpoints</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_nb_bands</span> <span class="o">=</span> <span class="n">nb_bands</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nb_bands</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        returns the number of bands in the band structure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nb_bands</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nb_kpoints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the number of k-points in the band structure calculation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nb_kpoints</span>

<div class="viewcode-block" id="Wavederf.get_elements_between_bands"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Wavederf.get_elements_between_bands">[docs]</a>    <span class="k">def</span> <span class="nf">get_elements_between_bands</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">band_i</span><span class="p">,</span> <span class="n">band_j</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method returning a numpy array with elements</span>

<span class="sd">        [cdum_x_real, cdum_x_imag, cdum_y_real, cdum_y_imag, cdum_z_real, cdum_z_imag]</span>

<span class="sd">        between bands band_i and band_j (vasp 1-based indexing) for all kpoints.</span>

<span class="sd">        Args:</span>
<span class="sd">            band_i (Integer): Index of band i</span>
<span class="sd">            band_j (Integer): Index of band j</span>

<span class="sd">        Returns:</span>
<span class="sd">            a numpy list of elements for each kpoint</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">band_i</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">band_i</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span> <span class="ow">or</span> <span class="n">band_j</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">band_j</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_bands</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Band index out of bounds&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[:,</span> <span class="n">band_i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">band_j</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="p">:]</span></div></div>


<div class="viewcode-block" id="Waveder"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Waveder">[docs]</a><span class="k">class</span> <span class="nc">Waveder</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class for reading a WAVEDER file.</span>
<span class="sd">    The LOPTICS tag produces a WAVEDER file.</span>
<span class="sd">    The WAVEDER contains the derivative of the orbitals with respect to k.</span>
<span class="sd">    Author: Kamal Choudhary, NIST</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">gamma_only</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            filename: Name of file containing WAVEDER.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
            <span class="k">def</span> <span class="nf">readData</span><span class="p">(</span><span class="n">dtype</span><span class="p">):</span>
                <span class="sd">&quot;&quot;&quot; Read records from Fortran binary file and convert to</span>
<span class="sd">                np.array of given dtype. &quot;&quot;&quot;</span>
                <span class="n">data</span> <span class="o">=</span> <span class="sa">b</span><span class="s1">&#39;&#39;</span>
                <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">prefix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="n">data</span> <span class="o">+=</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">prefix</span><span class="p">))</span>
                    <span class="n">suffix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">fromfile</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
                    <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">prefix</span><span class="p">)</span> <span class="o">-</span> <span class="nb">abs</span><span class="p">(</span><span class="n">suffix</span><span class="p">):</span>
                        <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Read wrong amount of bytes.</span><span class="se">\n</span><span class="s2">&quot;</span>
                                           <span class="s2">&quot;Expected: </span><span class="si">%d</span><span class="s2">, read: </span><span class="si">%d</span><span class="s2">, suffix: </span><span class="si">%d</span><span class="s2">.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="n">suffix</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">prefix</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                        <span class="k">break</span>
                <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">frombuffer</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span>

            <span class="n">nbands</span><span class="p">,</span> <span class="n">nelect</span><span class="p">,</span> <span class="n">nk</span><span class="p">,</span> <span class="n">ispin</span> <span class="o">=</span> <span class="n">readData</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">)</span>
            <span class="n">_</span> <span class="o">=</span> <span class="n">readData</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)</span>  <span class="c1"># nodes_in_dielectric_function</span>
            <span class="n">_</span> <span class="o">=</span> <span class="n">readData</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)</span>  <span class="c1"># wplasmon</span>
            <span class="k">if</span> <span class="n">gamma_only</span><span class="p">:</span>
                <span class="n">cder</span> <span class="o">=</span> <span class="n">readData</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">cder</span> <span class="o">=</span> <span class="n">readData</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">complex64</span><span class="p">)</span>

            <span class="n">cder_data</span> <span class="o">=</span> <span class="n">cder</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="n">ispin</span><span class="p">,</span> <span class="n">nk</span><span class="p">,</span> <span class="n">nelect</span><span class="p">,</span> <span class="n">nbands</span><span class="p">))</span><span class="o">.</span><span class="n">T</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">_cder_data</span> <span class="o">=</span> <span class="n">cder_data</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_nkpoints</span> <span class="o">=</span> <span class="n">nk</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ispin</span> <span class="o">=</span> <span class="n">ispin</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_nelect</span> <span class="o">=</span> <span class="n">nelect</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_nbands</span> <span class="o">=</span> <span class="n">nbands</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">cder_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the orbital derivative between states</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cder_data</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nbands</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the number of bands in the calculation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nbands</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nkpoints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the number of k-points in the calculation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nkpoints</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">nelect</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the number of electrons in the calculation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_nelect</span>

<div class="viewcode-block" id="Waveder.get_orbital_derivative_between_states"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.Waveder.get_orbital_derivative_between_states">[docs]</a>    <span class="k">def</span> <span class="nf">get_orbital_derivative_between_states</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">band_i</span><span class="p">,</span> <span class="n">band_j</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">,</span> <span class="n">spin</span><span class="p">,</span> <span class="n">cart_dir</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method returning a value</span>
<span class="sd">        between bands band_i and band_j for k-point index, spin-channel and cartesian direction.</span>
<span class="sd">        Args:</span>
<span class="sd">            band_i (Integer): Index of band i</span>
<span class="sd">            band_j (Integer): Index of band j</span>
<span class="sd">            kpoint (Integer): Index of k-point</span>
<span class="sd">            spin   (Integer): Index of spin-channel (0 or 1)</span>
<span class="sd">            cart_dir (Integer): Index of cartesian direction (0,1,2)</span>

<span class="sd">        Returns:</span>
<span class="sd">            a float value</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">band_i</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">band_i</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nbands</span> <span class="o">-</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">band_j</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">band_j</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nelect</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Band index out of bounds&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">kpoint</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nkpoints</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;K-point index out of bounds&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">cart_dir</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="ow">or</span> <span class="n">cart_dir</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;cart_dir index out of bounds&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cder_data</span><span class="p">[</span><span class="n">band_i</span><span class="p">,</span> <span class="n">band_j</span><span class="p">,</span> <span class="n">kpoint</span><span class="p">,</span> <span class="n">spin</span><span class="p">,</span> <span class="n">cart_dir</span><span class="p">]</span></div></div>


<div class="viewcode-block" id="UnconvergedVASPWarning"><a class="viewcode-back" href="../../../../pymatgen.io.vasp.outputs.html#pymatgen.io.vasp.outputs.UnconvergedVASPWarning">[docs]</a><span class="k">class</span> <span class="nc">UnconvergedVASPWarning</span><span class="p">(</span><span class="ne">Warning</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Warning for unconverged vasp run.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">pass</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.vasp.outputs</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>